Can I get viewstate data during Page.OnInit

Discussion in 'ASP .Net' started by Donal McWeeney, Nov 17, 2004.

  1. 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 McWeeney, Nov 17, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%23A%...
    > 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
    >
    >
    Jeffrey Palermo [MCP], Nov 18, 2004
    #2
    1. Advertising

  3. 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.)
    Steven Cheng[MSFT], Nov 18, 2004
    #3
  4. Thanks for the confirmation guys...

    Thanks

    Donal
    Donal McWeeney, Nov 18, 2004
    #4
  5. "Donal McWeeney" <> wrote in message
    news:%23A%...
    > 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
    John Saunders, Nov 18, 2004
    #5
  6. You're welcome, Donal.
    Steven Cheng[MSFT], Nov 19, 2004
    #6
  7. 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:...
    > "Donal McWeeney" <> wrote in message
    > news:%23A%...
    >> 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
    >
    >
    Donal McWeeney, Nov 19, 2004
    #7
  8. "Donal McWeeney" <> wrote in message
    news:u1%...
    > 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
    John Saunders, Nov 19, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    539
    Natty Gur
    Jul 13, 2003
  2. Guest
    Replies:
    2
    Views:
    3,084
    Guest
    Jul 16, 2003
  3. Invalidlastname
    Replies:
    7
    Views:
    810
    Steven Cheng[MSFT]
    Jan 16, 2004
  4. Sally
    Replies:
    1
    Views:
    467
    bruce barker
    Apr 15, 2004
  5. Peter Zolja

    Access container during OnInit

    Peter Zolja, Jan 30, 2007, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    108
    Peter Zolja
    Jan 30, 2007
Loading...

Share This Page