Calling the ASP.NET Controls using jQuery




As we all know the jQuery is one of the most powerful javascript library which simplifies the HTML DOM elements traversing,event handling e.t.c.  Please go through this where you can call the ASp.NET controls using jQuery.  One thing, while creating object of any ASP.NET control, always use ClientID. As when Master pages are used then the ID of the ASP.NET controls is changed at run time.


1. Getting the Label Text

     E.g:$('#<%=Label1.ClientID%>').text();

2. Set the label Text

E.g:$('#<%=Label1.ClientID%>').text("New Value");

3. Set TextBox Text

E.g:$('#<%=TextBox1.ClientID%>').val("New Value");

4. Get Dropdown value:

E.
g:$('#<%=DropDownList1.ClientID%>').val();

5. Set Dropdown value:

E.
g:$('#<%=DropDownList1.ClientID%>').val("New Value");

6. Get text of selected item in dropdown:

E.g:$('#<%=DropDownList1.ClientID%> option:selected').text();

7. Get Checkbox Status:

E.g:$('#<%=CheckBox1.ClientID%>').attr('checked');

8. Check the Checkbox:

E.g
:$('#<%=CheckBox1.ClientID%>').attr('checked',true);

9. Uncheck the Checkbox:

E.g:$('#<%=CheckBox1.ClientID%>').attr('checked',false);

10. Get Radiobutton Status:

E.g:$('#<%=RadioButton1.ClientID%>').attr('checked');

11. Check the RadioButton:

E.g:$('#<%=RadioButton1.ClientID%>').attr('checked',true);

12. Uncheck the RadioButton:

E.g:$('#<%=RadioButton1.ClientID%>').attr('checked',false);

13. Disable any control:

E.g:$('#<%=TextBox1.ClientID%>').attr('disabled', true);

14. Enable any control:

E.g:$('#<%=TextBox1.ClientID%>').attr('disabled', false);

15
. Make textbox read only:

E.g:$('#<%=TextBox1.ClientID%>').attr('readonly', 'readonly');

I found these are the normal requirements
in my experience.  Please share your code snippets other than this examples.