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))
{}
}
31ef03c9-076c-4275-9787-4ac1f57895bf|0|.0
Views: 929
Tags:
.Net | ASP.Net