Set name attribute for HtmlInputHidden or hidden input control

by Viper 28. January 2009 12:26

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))
 {}
}

Views: 929

Tags:

.Net | ASP.Net

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli