Well it’s official - I’m the newest member of the jQuery fan club. Since Microsoft announced their partnership with the jQuery team and it’s integration with Visual Studio – I’ve been all over it.
I am amazed at how fast it’s taken off in the short time it’s been around. People are writing and publishing plugins like crazy.
As my first jQuery post, I thought I’d show a few basic examples of interacting with some of the common ASP.NET server controls.
DropDownList SelectedValue:
GET: $('#<%=DropDownList1.ClientID%>').val()
SET: $('#<%=DropDownList1.ClientID%>').val("value_to_set")DropDownList SelectedIndex (2 options):
GET: $('#<%=DropDownList1.ClientID%>').attr("selectedIndex")
GET: $('#<%=DropDownList1.ClientID%>')[0].selectedIndex
SET: $('#<%=DropDownList1.ClientID%>').attr("selectedIndex", "0")
SET: $('#<%=DropDownList1.ClientID%>')[0].selectedIndex = 0RadioButtonList SelectedValue:
GET: $("input[name='<%=RadioButtonList1.UniqueID%>']:checked").val()
SET: $("input[name='<%=RadioButtonList1.UniqueID%>'][value='value_to_set']").attr("checked", true)Button Enable/Disable
$('#<%=Button1.ClientID%>').attr("disabled", true/false);Label Text
GET: $('#<%=Label1.ClientID%>').text()
SET: $('#<%=Label1.ClientID%>').text("value_to_set")TextBox Text (also HiddenField Value)
GET: $('#<%=TextBox1.ClientID%>').val()
SET: $('#<%=TextBox1.ClientID%>').val("value_to_set")Check Visibility
if ($('#<%=Button1.ClientID%>').is(':visible'))That’s it for now. More to come-
no example for setting RadioButtonList SelectedValue ?
ReplyDeletephilpill-
ReplyDeleteSorry, I completely overlooked the SET for the RadioButtonList. I've now added it to the list.
Thanks-
Hello Kenneth,
ReplyDeleteThats great man, thanks for this valuable info.
www.aspnetnova.blogspot.com
nice blog...
ReplyDeletevisit also asp.net example
FYI...for RadioButtonList. Remove the @ symbol from "@value".
ReplyDeleteThe way listed above was marked deprecated in v1.2 and completely removed in v1.3. The correct way in v1.3 is to remove the @ from @value otherwise the rest is the same. We only noticed it after upgrading from v1.2 to v1.3 of JQuery.
Timm Hagen
Hey Timm-
ReplyDeleteThanks for the info - I will update the post right now.
Kenneth