tags:

views:

222

answers:

2

I have a serverside dropdownlist and I am accessing it's id in jquery like this

$('#<%=ddldropdownlist.clientID%>')

I have a asp:LinkButton inside a gridview and I want to access it's client ID.

when I do as above in jquery it doesn't work

I think that's not the correct way since the server control is inside another server control

Could someone please help

+2  A: 

The ClientID of the LinkButton is going to get mangled once it's within a repeating control like a GridView or a ListView. If you need a way to access the LinkButton you can assign a unique class name to them like "link-thing" and then use that within jQuery like so:

$(".link-thing")...
CAbbott
I concur. ASP.NET will tear up the expected clientID's of controls. Using a unique 'class' though will make it easier for jQuery to walk through the DOM and find the items that you're looking for.
Chris
A: 

You have a few of options:

The most common would be to assign a custom class or attribute to the button that you can use as a selector.

The other way would be to implement the OnDataBinding event for the button and then assign the ClientID of the control from the OnDataBinding sender to your Jquery call in this function for each control assuming you are trying to hookup some Jquery to your button.

You could also use the OnDataBinding method to build up a hidden field with a list of ClientID names.

The best solution is probably to get a selector working but there are cases where the OnDataBinding works great as well.

Kelsey