Kathy Judd
Kathy Judd

Reputation: 737

How to select an asp.net control using ID in Jquery?

I have a webform with some asp.net controls and I would like to select each control using their ID. When I launch the page all the names get changed.

Is there an easy way to use this. I would prefer not use class as a selector.

Upvotes: 1

Views: 1126

Answers (2)

Dgan
Dgan

Reputation: 10295

After Rendering controls id will chaged something like cph_master_labelid

using jquery

var id=$(#'<%labelid.ClientID %>')

or You can Set its server side Property [Control.ClientIDMode][1]" Used only in 4.0 or greater

<asp:Label id="mylabel" runat="server" ClientIDMode="Static" />

Upvotes: 3

Atsso
Atsso

Reputation: 98

If you are using asp.net 4 you can set the ClientIDMode tag to Static. That will prevent asp.net from changing the ID of the controls.

    <asp:Button ClientIDMode="Static" />

Upvotes: 5

Related Questions