Jquery Selector for asp.net web form controls

This post will tell you about Jquery Selector for asp.net web form controls. JQuery selectors are used to select the DOM element using their id’s, class, element name, attribute value etc.

If you want to select an element by it’s ID when using asp.net web form. It could be a little bit tricky, because server side controls have their ID auto generate.

 

Solution:

When you see the id of server side controls generated in such way it has a prefix to the ID that you have defined for that control.

eg. If you give id to your element as txtName it will generate ID like ct_100_PlaceHolderMain_ct100_txtname

The ID that you specified will be in the end of the id generated automatically.

You can select such elements by their ID as

$(‘[id$=”_txtName”]’).v(<set the value here>);

This line specifies the control has the ID ends with _txtName

 

Enjoy…!!