Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a texbox:
<asp:TextBox ID="txtname" runat="server">

For required field validation I wrote script as:

$(document).ready(function () {
$("#form1").validate({
rules: {

&lt;%=txtname.UniqueID%>:{
required:true
},
},
messages: {

&lt;%=txtname.UniqueID%>:{
required: "Name is required."
},
},
});
});

Its shows error in line '<%=txtname.UniqueID%>:'expected identifier,string or number.
Actually what it means.

What I have tried:

set textbox property as ClientIDMode="Static" instead of <%=txtname.UniqueID%>
use simply control Id <%=txtname%> but still not work.
Posted
Updated 15-Jun-17 2:21am
Comments
F-ES Sitecore 8-Jun-17 5:28am    
Is this javascript on the aspx page or in a js file?
Member 13174150 8-Jun-17 5:39am    
on aspx page
F-ES Sitecore 8-Jun-17 5:51am    
View the page source and check the js being generated. I don't know if it's how your formatted the code, but if what you've posted is literally what you have on the aspx page then it's not going to work, you need this

"<%=txtname.UniqueID%>":{
Member 13174150 8-Jun-17 8:54am    
Thank you

1 solution

Follow these steps:

<asp:TextBox ID="txtname" runat="server">

To get id for performing any client side validation use this:
JavaScript
var obj = document.getElementById('<%=txtname.ClientID%>');

This will solve your problem and will be help full in future
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900