0

I am using jQuery validation plugin( latest version downloaded, added in my project) in asp.net project. The problem is, my validation rules are in a separate js file. So when I type in <%=textbox.UniqueID%> I get an error - Expected identifier, string or number. I added quotes to make it a string - "<%=textbox.UniqueID%>" and now its just viewed as a string - it does not get the unique id of the text box. But when I put these validations in .aspx page it's working fine but this is not I want, I want to put validations in separate js file

Here is what I have tried

filename: customscript.js

$("#form1").validate({

        rules: {
                <%= txtOtprId.UniqueID %>: //here I am getting error   Expected identifier, string or number
                {
                    required: true,
                    alphanumeric: true,
                    minlength: 12,
                    maxlength: 12
                },
                <%= txtName.UniqueID %>: //here i am getting error
                {
                    required: true,
                    lettersonly: true
                }
          }
      });
3
  • ASP code will not be evaluated in a JavaScript file, so whatever you put there will be treated as literal text. Commented May 22, 2019 at 14:35
  • The <%= %> items are meant to be replaced by the server when it renders the page. However, the server does not render .js files, nor would it know what txtOtprId is if that control is specified in another file. Commented May 22, 2019 at 14:35
  • Thanx, I got found an answer in below link, stackoverflow.com/questions/619816/… it would help somebody :) Commented May 23, 2019 at 9:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.