Get the Client ID of an ASP.NET Control in jQuery

While navigating the DOM using jQuery, it is often necessary to get the id of the control and perform operations on it, like hiding the control.

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="">

<head runat="server">


<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function() {

        $("#<%=RadioButtonList1.ClientID %>").hide('slow');





<form id="form1" runat="server">


<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>


The example shown above fetches the ClientId of the RadioButtonList and hides it using jQuery

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal


jQuery beginner said...

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" />

The only way I seem to get hold of the control is to get it's full name from the source code:


Just don't think it is as pretty. Anyone who can help?!

Suprotim Agarwal said...

Are you getting this error in all browsers or just in Chrome?

jQuery beginner said...

you're right... at least it works in explorer. Thanks!