A
alun65
I need to access a hidden HTML field on post back from the OnInit
method. This hidden field value has been set previously in the
Page_load event.
simplified example is as follows: IN THE CODE BEHIND
protected override void OnInit(EventArgs e)
{
Label1.Text = myHiddenFeild.Value;
}
protected void Page_Load(object sender, EventArgs e)
{
myHiddenFeild.Value = "Hello World";
}
protected void Button1_Click(object sender, EventArgs e)
{
//Just added so I could postBack
}
IN THE ASPX PAGE:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="hidden" runat="server" id="myHiddenFeild" />
<asp:Label ID="Label1" runat="server" Text="Label"></
asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
Expected Result
---------------------
When I press the button the label is updated with the hidden field
value " Hello World".
Actual Result
-------------------
Is nothing happens.
Debugging
-----------------
When debugging the hidden field value (myHiddenFeild) is empty in the
Oninit method, but as soon as it the execution reaches the Page_load
method then the myHiddenFeild as a value again.
Sorry if I'm being dense and staring the obvious in the face. As
always many thanks for any replys.
Cheers
Alun
method. This hidden field value has been set previously in the
Page_load event.
simplified example is as follows: IN THE CODE BEHIND
protected override void OnInit(EventArgs e)
{
Label1.Text = myHiddenFeild.Value;
}
protected void Page_Load(object sender, EventArgs e)
{
myHiddenFeild.Value = "Hello World";
}
protected void Button1_Click(object sender, EventArgs e)
{
//Just added so I could postBack
}
IN THE ASPX PAGE:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="hidden" runat="server" id="myHiddenFeild" />
<asp:Label ID="Label1" runat="server" Text="Label"></
asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
Expected Result
---------------------
When I press the button the label is updated with the hidden field
value " Hello World".
Actual Result
-------------------
Is nothing happens.
Debugging
-----------------
When debugging the hidden field value (myHiddenFeild) is empty in the
Oninit method, but as soon as it the execution reaches the Page_load
method then the myHiddenFeild as a value again.
Sorry if I'm being dense and staring the obvious in the face. As
always many thanks for any replys.
Cheers
Alun