However, if you are using an ASP.NET Master Page and would like to retrieve the ClientId of a control using jQuery, then here's how to do so:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#<%=RadioButtonList1.ClientID %>").hide('slow');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="Ten"></asp:ListItem>
<asp:ListItem Value="Twenty"></asp:ListItem>
<asp:ListItem Value="Thirty"></asp:ListItem>
<asp:ListItem Value="Forty"></asp:ListItem>
</asp:RadioButtonList>
The example shown above fetches the ClientId of the RadioButtonList and hides it using jQuery
Tweet
3 comments:
I'm trying to use the above to hide control, but get bellow error message:
$("#<%=dropDownNotification.ClientID %>").hide();
TypeError: Cannot set property 'display' of undefined
my control look like this:
<asp:DropDownList ID="dropDownNotification" runat="server">
<asp:ListItem Value="0" Text="Begge" Selected="True" />
<asp:ListItem Value="1" Text="SMS" />
<asp:ListItem Value="2" Text="E-mail" />
</asp:DropDownList>
The only way I seem to get hold of the control is to get it's full name from the source code:
$("#ctl00_ContentPlaceHolder1_dropDownNotification").hide();
Just don't think it is as pretty. Anyone who can help?!
Are you getting this error in all browsers or just in Chrome?
you're right... at least it works in explorer. Thanks!
Post a Comment