1

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.

2 Answers 2

5

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" />
Sign up to request clarification or add additional context in comments.

2 Comments

That's too simple. Thanks
@KathyJudd You can set this at the web.config level so that you don't have to add ClientIdMode="Static" for every control you want to reference. See here. You can also set it at the page level.
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.