How to Access ASP.NET Controls client id in JQuery

You are using JQuery with ASP.NET and you want to access client ids of ASP.NET controls in JQuery.

When ASP.NET renders server side controls it gives them unique client ids which are different from their server ids and if you check view source of your ASP.NET page you will find ids familiar to following.


This id can be even more lengthy if you are using Master pages in your ASP.NET website. So how you can access these controls in JQuery. The quick workarround is to use following technique.

$("#'<%=txtName.ClientID %>'");

Another approach which enables you to avoid server tags completely is to match the elements by the end part of their names like following example.




About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies