- There are many developers that are depend on intellisense provided by Microsoft Visual Studio.
- But some times it may not work for scripting, though in VS 2012 and higher version it quite run much good.
- So here are some of the JS code that I would like to share with developers for accessing the .NET controls and how to retrieve and set value to controls.
- Get Label Value:
- $('#<%=Label.ClientID%>').text();
- $('#<%=Label.ClientID%>').text("New Value");
- Get Textbox value:
- $('#<%=TextBox.ClientID%>').val();
- $('#<%=TextBox.ClientID%>').val("New Value");
- $('#<%=DropDownList.ClientID%>').val();
- $('#<%=DropDownList.ClientID%>').val("New Value");
- $('#<%=DropDownList.ClientID%> option:selected').text();
- $('#<%=CheckBox.ClientID%>').attr('checked');
- $('#<%=CheckBox.ClientID%>').attr('checked',true);
- $('#<%=CheckBox.ClientID%>').attr('checked',false);
- Get Radiobutton Status:
- $('#<%=RadioButton.ClientID%>').attr('checked');
- $('#<%=RadioButton.ClientID%>').attr('checked',true);
- $('#<%=RadioButton.ClientID%>').attr('checked',false);
- $('#<%=TextBox.ClientID%>').attr('disabled', true);
- $('#<%=TextBox.ClientID%>').attr('disabled', false);
- $('#<%=TextBox.ClientID%>').attr('readonly', 'readonly');
- For getting the data you may also use as what I have said in previous blog, that is simpler
No comments:
Post a Comment