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.