In many forums I have read that dynamic controls have to be loaded during Page_Init method. But I am finding problem with this.
I have a GridView and a TabControl. On click on the row of grid, I store the EmpId in a hiddenfield in javascript. Now in Page_Init, I am trying to load a usercontrol for a EmpId stored in hiddenfiled. But I am not able to access hiddenfield value in the
Page_Init. It display empty. If I have to load the usercontrol during Page_Init, then I have to access the HiddenField value first and it is give problem.
In many forums I have read that dynamic controls have to be loaded during Page_Init method.
For my experience ,there are two events of page are related to create or - recreate controls(read or initialize control properties).
1.PreInit event which is raised after the start stage is complete and before the initialization stage begins.
You can use the event for the following:
1.Check the IsPostBack property to determine whether this is the first time the page is being processed. The IsCallback and IsCrossPagePostBack properties have also been set at this time.
2.Create or re-create dynamic controls.
3.Set a master page dynamically.
4.Set the Theme property dynamically.
5.Read or set profile property values.
2.Init event which is raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before the Init event of the page.
You can use this event to read or initialize control properties.
CodeNT
But I am not able to access hiddenfield value in the Page_Init. It display empty.
I would like to suggest you that please use Request in Page Init event to get the value of hiddenfield control.
Please check the sample below ,hope it can help you.
CodeNT
Member
2 Points
15 Posts
HiddenField and Viewstate not accessible during Page_Init method.
Nov 26, 2010 06:27 AM|LINK
In many forums I have read that dynamic controls have to be loaded during Page_Init method. But I am finding problem with this.
I have a GridView and a TabControl. On click on the row of grid, I store the EmpId in a hiddenfield in javascript. Now in Page_Init, I am trying to load a usercontrol for a EmpId stored in hiddenfiled. But I am not able to access hiddenfield value in the Page_Init. It display empty. If I have to load the usercontrol during Page_Init, then I have to access the HiddenField value first and it is give problem.
Hence, is there any way to resolved this problem.
shahed.kazi
All-Star
17955 Points
3636 Posts
Re: HiddenField and Viewstate not accessible during Page_Init method.
Nov 26, 2010 07:46 AM|LINK
I don't think you can access the control on Init method as the controls have not been created yet.
.NET World |Captcha Control
Ming Xu - MS...
All-Star
25269 Points
2235 Posts
Microsoft
Re: HiddenField and Viewstate not accessible during Page_Init method.
Dec 01, 2010 06:47 AM|LINK
Hi,
For my experience ,there are two events of page are related to create or - recreate controls(read or initialize control properties).
1.PreInit event which is raised after the start stage is complete and before the initialization stage begins.
You can use the event for the following:
1.Check the IsPostBack property to determine whether this is the first time the page is being processed. The IsCallback and IsCrossPagePostBack properties have also been set at this time.
2.Create or re-create dynamic controls.
3.Set a master page dynamically.
4.Set the Theme property dynamically.
5.Read or set profile property values.
2.Init event which is raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before the Init event of the page.
You can use this event to read or initialize control properties.
I would like to suggest you that please use Request in Page Init event to get the value of hiddenfield control.
Please check the sample below ,hope it can help you.
1.Code in page(.aspx):
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function SetValueToHidden() { var hidden = document.getElementById("HiddenField1"); var text = document.getElementById("TextBox1"); hidden.value = text.value; } </script> </head> <body> <form id="form1" runat="server"> <div> Input text:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="ShowText" OnClientClick="SetValueToHidden()" /> <asp:HiddenField ID="HiddenField1" runat="server" /> </div> </form> </body> </html>2.Code in page(.cs):
protected void Page_Init(object sender, EventArgs e) { if (Request["HiddenField1"] != null) { Response.Write(Request["HiddenField1"].ToString()); } }Feedback to us
Develop and promote your apps in Windows Store