Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net HiddenField: add custom attribute dynamically

Tags:

asp.net

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?

like image 925
lekso Avatar asked Nov 29 '12 12:11

lekso


1 Answers

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";
like image 89
Oleks Avatar answered Oct 02 '22 23:10

Oleks