Set name attribute for HtmlInputHidden or hidden input control

While developing a custom control I discovered a very important thing related to how all key value pairs in FORM on a page get named and added. I had a hidden input field added to the page. I was only setting ID of the control but was not specifying the name attribute for it. On PostBack i was not getting my field back. May be I was but i did not see any key named as "name" that I specified for the control. Then I set "name" attribute for the control, and I was able to get the value set in that hidden input field back during post back.


HtmlGenericControl selectedObjField = new HtmlGenericControl("input");
selectedObjField .Attributes.Add("type", "hidden");
selectedObjField .Attributes.Add("id", "_selected_cms_list");
selectedObjField .Attributes.Add("name", "_selected_objs_list");
mainPanel.Controls.Add(selectedObjField );


if (this.Page.IsPostBack)
{
 string selectedCMs = this.Page.Request["_selected_objs_list"];
 if (!string.IsNullOrEmpty(selectedCMs))
 {}
}

Search

Social

Weather

-0.8 °C / 30.6 °F

weather conditions Mist

Monthly Posts

Blog Tags