0

I assign a value to an ASP hidden field within the page load but can't access that value in my JQuery. I added an alert as a test and it comes up 'undefined'. Am I making a syntactic error?

<asp:HiddenField runat="server" id="hfID"/>
hfID.Value = "Test";
alert($('#hfID').Val());
Borges
  • 17
  • 6
  • Check this [post](https://stackoverflow.com/questions/8908340/get-the-value-of-an-asphiddenfield-using-jquery). The id of asp controls is generated by the view engine. That's why your jquery selector don't work. – 4D1C70 Nov 03 '17 at 21:29

1 Answers1

0

Asp.Net Webforms mangles the id you give it to make sure it's unique on the page. You can use class as a selector or modify your jQuery selector so that it's looking for an id that ends in hfID.

$("[id$='hfID']")
ScoobyDrew18
  • 633
  • 9
  • 20