How can I add a custom attribute to a HiddenValueField in ASP.NET? Specifically, I need a class="gmapPoint" attribute for a dynamically generated HiddenValue control. This is necessary for a JavaScript on that page
var hiddenField = new HiddenField();
hfield.Value = "myValue";
hfield.... Attributes["class"]
-- how can I do a similar thing?
Use HtmlInputHidden
control instead of HiddenField
. It allows programmatic access to the HTML <input type=hidden>
element on the server and has .Attributes
property:
var hiddenField = new HtmlInputHidden();
hiddenField.Value = "myValue";
hiddenField.Attributes["class"] = "a-class-for-a-hidden-field";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With