467,210 Members | 1,400 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,210 developers. It's quick & easy.

Can I get viewstate data during Page.OnInit

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
Nov 18 '05 #1
  • viewed: 8287
Share:
7 Replies
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

"Donal McWeeney" <ma****@newsgroup.nospam> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2
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.)

Nov 18 '05 #3
Thanks for the confirmation guys...

Thanks

Donal
Nov 18 '05 #4
"Donal McWeeney" <ma****@newsgroup.nospam> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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
Nov 18 '05 #5
You're welcome, Donal.

Nov 18 '05 #6
Thanks John,

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

Thanks

Donal

"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:Ok*************@TK2MSFTNGP14.phx.gbl...
"Donal McWeeney" <ma****@newsgroup.nospam> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #7
"Donal McWeeney" <ma****@newsgroup.nospam> wrote in message
news:u1****************@tk2msftngp13.phx.gbl...
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
Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by theo | last post: by
9 posts views Thread by John Kirksey | last post: by
3 posts views Thread by Steve Drake | last post: by
6 posts views Thread by hlubocky@gmail.com | last post: by
2 posts views Thread by Rotsey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.