Can I get viewstate data during Page.OnInit

  • Thread starter Thread starter Donal McWeeney
  • Start date Start date
D

Donal McWeeney

Hi,

I'm round-tripping some values my page requires using hidden form fields -
my page class requires these values in its OnInit event.

I would like to be able to use viewstate to do this - however the load
viewstate does not happen until after OnInit and before OnLoad.

Is there anything I can do to make the viewstate data available for my
OnInit code. Any pointers to examples gratefully accepted.

Thanks

Donal
 
Donal,
As you stated, viewstate reloads after OnInit and before the Load event.
Because of this, viewstate will never be available in the OnInit phase. Any
code that depends on viewstate must execute after viewstate is loaded. You
must code your page around this requirement.

Best regards,
Jeffrey Palermo
 
Hi Donal,

I think Jeffery's suggestion is reasonable since the LoadViewState occurs
after the page's Init event and can't be manually changed. Also, as the
asp.net Page's ViewState is based on the normal html input hidden field(
<input type="hidden" name="__VIEWSTATE"
value="fjk43j53kj43mefdSds/jfdsjfksdfdsm-" /> ) , if you do need to store
some custom datas in page and be retrieved in the sequential request before
the page's LoadViewSTate, I suggest you try putting some <input
type="hidden" ..> elements on the page and store datas in it. How do you
think ?
If there's any other questions, please feel free to post here. Thanks.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Donal McWeeney said:
Hi,

I'm round-tripping some values my page requires using hidden form fields -
my page class requires these values in its OnInit event.

I would like to be able to use viewstate to do this - however the load
viewstate does not happen until after OnInit and before OnLoad.

Why not just put the values in your own hidden form fields and read the
values in OnInit? Put them into an HtmlHidden control. No ViewState
involved.

John Saunders
 
Thanks John,

Thats what I am doing at the moment - just thought that ViewState would be
cleaner.

Thanks

Donal
 
Donal McWeeney said:
Thanks John,

Thats what I am doing at the moment - just thought that ViewState would be
cleaner.

It would be cleaner. Just not if you need it in OnInit...

Of course, if you're building custom controls, you can hide the ugliness
behind properties.

John Saunders
 
Back
Top