Useful jQuery code examples for ASP.NET Controls

Earlier I had posted about Using jQuery with ASP.NET and in this post, you will find list of some useful jQuery code example for ASP.NET controls that we use on daily basis. 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. Read more here.

Get label value:

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

Set label value:

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

Get Textbox value:

$('#<%=TextBox1.ClientID%>').val();

Set Textbox value:

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

Get Dropdown value:

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

Set Dropdown value:

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

Get text of selected item in dropdown:

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

Get Checkbox Status:

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

Check the Checkbox:

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

Uncheck the Checkbox:

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

Get Radiobutton Status:

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

Check the RadioButton:

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

Uncheck the RadioButton:

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

Disable any control:

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

Enable any control:

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

Make textbox read only:

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

Share your useful code as well (via commenting), I will add this into this list.

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...