Monday 19 February 2007

Getting a value from a control in the Page Init

The value of a control (e.g. textbox) is not available in PreInit.
As the value may be required (e.g to generate dynamic controls, set theme) it can be retrieved by accessing Http Request:

string selectedValue ;
if (Request.Form["txtNoOfRooms"] != null)
selectedValue = Request.Form["txtNoOfRooms"].ToString();


Uses name of control to retrieve value. Not each control only has 1 value.

Example taken from this article in Code Project