anass 90 anass 90 - 1 month ago 9
ASP.NET (C#) Question

how to stop the HTML input property from setting automatically the name attribute

i have a problem with an input that sets automatically the name attribute witch blocks a javascript code traitement, this is the input code before running it:

<asp:textbox ID="replace" runat="server" Name="passchk_pass" type="Password" Size="40"/>

and this is how it becomes after running:

<input name="ct$Main$ct$Tab$Edu$replace" id="Main_ct_Tab_Edu_replace" type="Password" size="40">

so im losing the name that i sets befor in order to get a js traitement, how can i stop the input to set automatically the name attribute?


Better access the TextBox by ID. You can use a static client ID mode for that.

<asp:textbox ID="replace" ClientIDMode="Static" runat="server" Name="passchk_pass" type="Password" Size="40"/>

This is not recommended however, since it can lead to duplicate ID's. Better is to make sure javascript get's the correct ID.

var textBoxId = "<%= replace.ClientID %>";

But if you really want to use the name to access the TextBox you can use UniqueID

var textBoxName = "<%= replace.UniqueID %>";