Accessing a Hidden HTML field in the OnInit() method

Accessing a Hidden HTML field in the OnInit() method

am 30.01.2008 07:45:31 von 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:



Untitled Page






asp:Label>




OnClick="Button1_Click" Text="Button" />






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

Re: Accessing a Hidden HTML field in the OnInit() method

am 30.01.2008 08:27:15 von mark

wrote in message
news:bb4ec0ba-bd50-4d32-8df2-84be83a60de0@d21g2000prf.google groups.com...

> Sorry if I'm being dense and staring the obvious in the face. As
> always many thanks for any replies.

When a page is posted back, page initialisation happens before ViewState has
been reloaded...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Accessing a Hidden HTML field in the OnInit() method

am 30.01.2008 16:31:53 von gnewsgroup

On Jan 30, 2:27=A0am, "Mark Rae [MVP]" wrote:
> wrote in message
>
> news:bb4ec0ba-bd50-4d32-8df2-84be83a60de0@d21g2000prf.google groups.com...
>
> > Sorry if I'm being dense and staring the obvious in the face. =A0As
> > always many thanks for any replies.
>
> When a page is posted back, page initialisation happens before ViewState h=
as
> been reloaded...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

In other words, (On)Init happens before Page_Load, right?

Re: Accessing a Hidden HTML field in the OnInit() method

am 30.01.2008 17:24:35 von mark

"gnewsgroup" wrote in message
news:1c31fa04-3341-4282-b34d-b7c210ba2006@d4g2000prg.googleg roups.com...

>>> Sorry if I'm being dense and staring the obvious in the face. As
>>> always many thanks for any replies.
>>
>> When a page is posted back, page initialisation happens before ViewState
>> has
>> been reloaded...
>
> In other words, (On)Init happens before Page_Load, right?

Yes.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net