1

How do I retain the "name" attribute of an input in an ASP.NET application?

I just went through how to retain the IDs, but unfortunately, the jquery validation plugin using the name attribute--hence I'm trying to retain the name.

Any help is appreciated.

Thanks!

<label>Name</label>
<input type="text" name="name" runat="server" /><br />

<label>Email</label>
<input type="text" email name="email" runat="server" /><br />

<label>Password</label>
<input type="text" password id="password" name="password"  runat="server" /><br />

<label>Verify Password</label>
<input type="text" verify id="verify" name="verify"  runat="server" /><br />

<asp:Button runat="server" ID="submit" Text="Submit" />

Comes out as:

<label>Name</label>

<input name="ctl00$ContentPlaceHolderBody$ctl00" type="text" /><br />



<label>Email</label>

<input name="ctl00$ContentPlaceHolderBody$ctl01" type="text" email="" /><br />



<label>Password</label>

<input name="ctl00$ContentPlaceHolderBody$password" type="text" id="password" password="" /><br />



<label>Verify Password</label>

<input name="ctl00$ContentPlaceHolderBody$verify" type="text" id="verify" verify="" /><br />



<input type="submit" name="ctl00$ContentPlaceHolderBody$submit" value="Submit" id="submit" />
Barrett Kuethen
  • 1,864
  • 7
  • 25
  • 33

2 Answers2

1

Use UniqueID property for getting names. If you want to get the name of email field, use like this <%=email.UniqueID%> inside the jquery for getting names <%=email.ClientID%> will yield the ID of the control

James Montagne
  • 77,516
  • 14
  • 110
  • 130
Prasanth
  • 3,029
  • 31
  • 44
0

If you're using 4.0 you could try setting ClientIDMode to Static. Other than that, I would suggest referencing the control by the ClientID (ID) or the UniqueID (Name) in jQuery:

var el = $("#<%=TextBox1.UniqueID%>");
if (el){
    var value = el.val();
}
James Johnson
  • 45,496
  • 8
  • 73
  • 110