Amit Kumar
Amit Kumar

Reputation: 1397

.Net Control Id like text box access original Id c#

Is it possible to retain controls id. e.g

<asp:TextBox ID="myTextBox" />

When I use F12 it show its id different as "ct00_Main_myTextBox" is there any way to set it as "yTextBox", I know its due to master page.

Thanks.

Upvotes: 0

Views: 159

Answers (2)

Learning
Learning

Reputation: 20001

keep ClientIDMode="Static" and follow the rest as suggested by jrummell in his reply

I would also recommend you to read this article here

Upvotes: 0

jrummell
jrummell

Reputation: 43077

You can set the ClientIDMode to Static.

<asp:TextBox ID="myTextBox" ClientIDMode="Static" />

If you are trying to reference this in javascript, you could also use the ClientID property to get the generated ID, regardless of the ClientIDMode.

document.getElementById("<%= myTextBox.ClientID %>");

Upvotes: 2

Related Questions