How to get “name” of a server control just like “ClientID” in javascript?

I want to apply validation through jquery in my forms and for that I require the "name" attribute of the TextBoxes on my form which are generated by the ASP.Net automatically. Is there any way I can get the name of elements in javascript just like:

<script>
'<%= txt.ClientID %>'
</script>

I am using the following type of jquery validation:

$(".selector").validate({
   rules: {
     // simple rule, converted to {required:true}
     name: "required",
     // compound rule
     email: {
       required: true,
       email: true
     }
   }
})

Answers


You might do it like this...

<script> 
  var textbox = '<%= txt.UniqueID %>';
</script> 

Or even...

<script> 
  $('#<%= txt.UniqueID %>').DoYourThing();
</script> 

<script>
'<%= txt.UniqueID %>'
</script>

You can use the same way you have mentioned

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $("#aspnetForm").validate({
            errorLabelContainer: "#messageBox",
            wrapper: "li",
            onsubmit: false,
            rules: {
                <%=txtName.UniqueID %>:{
                    required: true,
                    maxlength: 50
                },
                <%=ddlState.UniqueID %>:{
                    selectOne: true
                },
                <%=ddlCity.UniqueID %>:{
                    selectOne: true
                }

            }, 
            messages: 
            {
                <%=txtName.UniqueID %>:{
                    required: "<%=Resources.EnterNameValidationMessage %>",
                    maxlength: "<%=Resources.MaxLengthEnterNameValidationMessage %>"
                },
                <%=ddlState.UniqueID %>:{
                    selectOne: "<%=Resources.SelectStateValidationMessage %>"
                },
                <%=ddlCity.UniqueID %>:{
                    selectOne: "<%=Resources.SelectCityValidationMessage %>"
                }
            }
        });
    });


Need Your Help

Separation between TBox and ABox in Fuseki with TDB and Pubby

sparql jena semantic-web linked-data fuseki

For my current project I need to load a dataset and different ontologies and expose everything as linked data using Fuseki with TDB and Pubby. Pubby will take a data set from a single location and ...

Trouble understanding meaning of functional dependency notation (A - > BC)

database functional-dependencies

I'm having a hard time visualizing exactly what A->BC means, mainly what exactly BC does.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.