Viewstate access

Discussion in 'ASP .Net Web Controls' started by Amr Al Jarhi, Nov 25, 2004.

  1. Amr Al Jarhi

    Amr Al Jarhi Guest

    I have a webform, with a statically declared usercontrol in it...
    the usercontrol is actually a webcontrol ( inherits from class
    WebControl)
    this control has some child controls created dynamically at the event:
    CreateChildControls
    obviously this event is fired before the viewstate is loaded, so i
    cannot save or load anything from the viewstate.
    the question is: how can i use the viewstate from inside the
    usercontrol? Or if i cannot, what is the best practice to save and
    load volatile data
    between postbacks from within the usercontrol?
     
    Amr Al Jarhi, Nov 25, 2004
    #1
    1. Advertisements

  2. Ashish Kaila

    Ashish Kaila Guest

    Implement INamingContainer interface in your webcontrol and override
    LoadViewState and SaveViewState to save the state of your control.
    HTH
    Ashish

    "Amr Al Jarhi" <> wrote in message
    news:...
    > I have a webform, with a statically declared usercontrol in it...
    > the usercontrol is actually a webcontrol ( inherits from class
    > WebControl)
    > this control has some child controls created dynamically at the event:
    > CreateChildControls
    > obviously this event is fired before the viewstate is loaded, so i
    > cannot save or load anything from the viewstate.
    > the question is: how can i use the viewstate from inside the
    > usercontrol? Or if i cannot, what is the best practice to save and
    > load volatile data
    > between postbacks from within the usercontrol?
     
    Ashish Kaila, Nov 30, 2004
    #2
    1. Advertisements

  3. Guest

    Thank you Ashish for your reply. This approach was suggested to me, but
    to my specific purpose I have found that it is a little complicated. I
    thought that inheriting from webcontrol would be very similar to
    inheriting from usercontrol. My problem was solved by inheriting from
    usercontrol instead. I guess inheriting from the webcontrol class is
    not very usefull, unless I want to inherit from a specific webcontrol,
    like textbox, and utilize the base functionality. But obviuosly
    inheriting from the general webcontrol class does not give any
    particular advantage that I am aware of over inheriting from user
    control.
     
    , Dec 6, 2004
    #3
    1. Advertisements

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. Ben Rush
    Replies:
    2
    Views:
    745
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,867
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,535
    ujjc001
    Jul 27, 2005
  4. sck10
    Replies:
    6
    Views:
    1,182
    sck10
    Sep 1, 2006
  5. mark

    Viewstate errors... how do I get viewstate working?

    mark, Feb 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    413
Loading...

Share This Page