错误解决服务器端的标签 [英] Error in resolving server side tag
问题描述
无效前pression术语'<
< ASP:文本框ID =txtPassword=服务器
WIDTH =180像素的TextMode =密码
OnTextChanged =CheckPasswordStrength(小于%= txtPassword.ClientID.ToString()%>,&下;%= lblMessage.ClientID.ToString()%&GT)/>
如果我写发生此code像下面则错误未处理的异常已发生。服务器标记不能包含<%%>结构
< ASP:文本框ID =txtPassword=服务器
WIDTH =180像素的TextMode =密码
OnTextChanged =CheckPasswordStrength(&下;%= txtPassword.ClientID.ToString()%>中,&下;%= lblMessage.ClientID.ToString()%>中)/>
当我米用在此的.cs code文件,然后每一件事工作正常。
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
txtPassword.Attributes.Add(的onkeyup,PasswordCheck(+ txtPassword.ClientID.ToString()+));
txtPrimaryEmail.Attributes.Add(的onkeyup,EmailChecker(+ txtPrimaryEmail.ClientID.ToString()+));
}
有几件事情发生的事情与这个..你不能在你的服务器端事件的参数,你不能使用<% =以服务器控件。
您的意思火JavaScript事件?
如果你的意思解雇一个JavaScript事件,做的三件事之一:
1)使用数据绑定前pression(LT;%#Control.ClientID%>) - 这要求整个生命周期内的某处的DataBind()被调用你的控制
2)分配在$ C $事件的c-后面,采用Control.Attributes.Add(javascriptevent,DoStuff(X,Y))
3)您可以使用<在客户端脚本%=%>,例如
函数MyJavaScriptEventHandler()
{
VAR文本=的document.getElementById('<%= MyASPTextBox.ClientID%GT;');
警报(textbox.value);
}
Invalid expression term '<'
<asp:TextBox ID="txtPassword" runat="server"
Width="180px" TextMode="Password"
OnTextChanged="CheckPasswordStrength(<%= txtPassword.ClientID.ToString() %>,<%= lblMessage.ClientID.ToString() %>)"/>
If i writes this code like the following then error occurs An unhandled exception has occured. Server tags cannot contain <% %> constructs
<asp:TextBox ID="txtPassword" runat="server"
Width="180px" TextMode="Password"
OnTextChanged="CheckPasswordStrength("<%= txtPassword.ClientID.ToString() %>","<%= lblMessage.ClientID.ToString() %>")"/>
When I m using this code at .cs file then every thing is working fine.
protected void Page_Load(object sender, EventArgs e)
{
txtPassword.Attributes.Add("onKeyUp", "PasswordCheck("+txtPassword.ClientID.ToString()+")");
txtPrimaryEmail.Attributes.Add("onKeyUp", "EmailChecker("+txtPrimaryEmail.ClientID.ToString()+")");
}
There are a couple things going on with this.. You can't include parameters in your server-side event, and you can't use <%= in a server control.
Are you meaning to fire a JavaScript event?
If you're meaning to fire a JavaScript event, do one of three things:
1) Use a databinding expression (<%# Control.ClientID %>) - This requires that somewhere within the life-cycle DataBind() is being called on your control.
2) Assign the event in the code-behind, using Control.Attributes.Add("javascriptevent", "DoStuff(x, y)")
3) You can use <%= %> in your client script, e.g.
function MyJavaScriptEventHandler()
{
var textbox = document.getElementById('<%= MyASPTextBox.ClientID %>');
alert(textbox.value);
}
这篇关于错误解决服务器端的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!