We are trying to write a form at ASP.net using visual studio.
We want to be able to control the final client side ID of elements so we can refer to them in the jquery code easily.
The regular 'id' attribute at ASP.net gets an odd prefix that we cannot control at the client side.
How can we fully control the final client side ID of an element?
<asp:TextBox ID="TBICDCode6" runat="server" Width="240">
I want to be able to refer to the text box using
If you are using ASP.NET 4.0, you can do this by setting
<asp:TextBox ID="TBICDCode6" runat="server" ClientIDMode="Static" Width="240"> </asp:TextBox>
Or, if you are using an older version of ASP.NET, try this.
$("#" + '<%= TBICDCode6.ClientID %>')
$("#<%= TBICDCode6.ClientID %>");
it's a well known fact that asp.net does nasty things to ids. it's supposed to be better in asp.net 4.0, but I haven't tried it yet.
try reading 'Referencing Server Controls in Client Script' here.
Alternatively, you can bypass the whole thing completly by using another attribute (such as
your selectors will then be
$("[name=someId]"), instead of