Wednesday, March 19, 2014

Get & Set Value in Web control

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:
view sourceprint?
 $('#<%=TextBox1.ClientID%>').attr('readonly', 'readonly'); 

No comments:

Post a Comment