Useful jQuery code examples for ASP.NET Controls
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.