Can I get viewstate data during Page.OnInit

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
 
J

Jeffrey Palermo [MCP]

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
 
S

Steven Cheng[MSFT]

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.)
 
J

John Saunders

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
 
D

Donal McWeeney

Thanks John,

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

Thanks

Donal
 
J

John Saunders

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top