Viewstate and Collections

Discussion in 'ASP .Net Web Controls' started by mark, Jan 7, 2004.

  1. mark

    mark Guest

    Hi there,

    I've got a problem. I need to store my server controls view state.
    This all seems very easy when dealing with simple properties, just pop
    them in the Viewstate bag and retrieve them when you need them.

    Problem for me is that I have a Server Control which is a form of
    datagrid display and it looks like the following: -

    My Server Control
    - ColumnHeaders (collection)
    - ColumnHeader (class)
    - HeaderButtons (collection)
    - Button (class)
    - DetailButtons (collection)
    - Button (class)
    - Rows (collection)
    - Row (collection)
    - Item (class)
    - ID (property
    - Title (property)
    - Datasource (method)
    - Etc...

    I've looked all over the net trying to find out how to save the
    viewstate of all my collections but I haven't found anything that
    helps. I've read about LoadViewState and SaveViewState and the
    IStateManager and seen examples using them but I haven't seen any
    examples that show the Container, Collection and Class.

    I guess that my collection and classes need to implement the
    IStateManger interface? Or is it just the collection?

    Do I need to use TrackViewState?

    I know these could be all very simple questions to answer, but they
    aren't for me! :-(

    Please help! What would be really useful would be just a short example
    in C# showing how it's done. I find that the best way to understand.

    Thank you in advance,

    Mark (in dire need) Bateman...
     
    mark, Jan 7, 2004
    #1
    1. Advertising

  2. hi mark,
    To improve efficiency, or to save a custom type that cannot be stored by
    default in ViewState, a control can customize how property data is stored in
    ViewState. If a control customizes storage of property data, the control
    must also provide a custom implementation for restoring property values from
    data stored in ViewState. the base class Control provides two methods for
    this purpose, SaveViewState and LoadViewState.
    And yes, you need to use trackviewstate. The examples shows everything in
    detail, give it a look :
    http://msdn.microsoft.com/library/d...html/cpcontemplateddataboundcontrolsample.asp


    "mark" <> wrote in message
    news:...
    > Hi there,
    >
    > I've got a problem. I need to store my server controls view state.
    > This all seems very easy when dealing with simple properties, just pop
    > them in the Viewstate bag and retrieve them when you need them.
    >
    > Problem for me is that I have a Server Control which is a form of
    > datagrid display and it looks like the following: -
    >
    > My Server Control
    > - ColumnHeaders (collection)
    > - ColumnHeader (class)
    > - HeaderButtons (collection)
    > - Button (class)
    > - DetailButtons (collection)
    > - Button (class)
    > - Rows (collection)
    > - Row (collection)
    > - Item (class)
    > - ID (property
    > - Title (property)
    > - Datasource (method)
    > - Etc...
    >
    > I've looked all over the net trying to find out how to save the
    > viewstate of all my collections but I haven't found anything that
    > helps. I've read about LoadViewState and SaveViewState and the
    > IStateManager and seen examples using them but I haven't seen any
    > examples that show the Container, Collection and Class.
    >
    > I guess that my collection and classes need to implement the
    > IStateManger interface? Or is it just the collection?
    >
    > Do I need to use TrackViewState?
    >
    > I know these could be all very simple questions to answer, but they
    > aren't for me! :-(
    >
    > Please help! What would be really useful would be just a short example
    > in C# showing how it's done. I find that the best way to understand.
    >
    > Thank you in advance,
    >
    > Mark (in dire need) Bateman...
     
    Alessandro Zifiglio, Jan 7, 2004
    #2
    1. Advertising

  3. make your collection implement IStateManager

    override TrackViewState,SaveViewState,LoadViewState as:

    override protected void TrackViewState()
    {
    base.TrackViewState();
    MyItems.TrackViewState();
    }
    override protected object SaveViewState()
    {
    return new Pair(base.SaveViewState(),MyItems.SaveViewState());
    }
    override protected void LoadViewState(object state)
    {
    Pair p=(Pair)state;
    if(p==null)return;
    base.LoadViewState(p.First);
    MyItems.SaveViewState(p.Second);
    }

    --
    http://www.lostinet.com/
    ---------------------------
    Lostinet.Web Controls&Components help you to build better Asp.Net
    CustomerControl&UserControl&Application.
    ---------------------------
    It's FREE !!
    ---------------------------
    ControlHelper&HelperElement for MessageBox&Dialog
    ComboBox,ComboCalendar,SmartIframe
    ---------------------------
    Remote Asp.Net Execution

    "mark" <> ????
    news:...
    > Hi there,
    >
    > I've got a problem. I need to store my server controls view state.
    > This all seems very easy when dealing with simple properties, just pop
    > them in the Viewstate bag and retrieve them when you need them.
    >
    > Problem for me is that I have a Server Control which is a form of
    > datagrid display and it looks like the following: -
    >
    > My Server Control
    > - ColumnHeaders (collection)
    > - ColumnHeader (class)
    > - HeaderButtons (collection)
    > - Button (class)
    > - DetailButtons (collection)
    > - Button (class)
    > - Rows (collection)
    > - Row (collection)
    > - Item (class)
    > - ID (property
    > - Title (property)
    > - Datasource (method)
    > - Etc...
    >
    > I've looked all over the net trying to find out how to save the
    > viewstate of all my collections but I haven't found anything that
    > helps. I've read about LoadViewState and SaveViewState and the
    > IStateManager and seen examples using them but I haven't seen any
    > examples that show the Container, Collection and Class.
    >
    > I guess that my collection and classes need to implement the
    > IStateManger interface? Or is it just the collection?
    >
    > Do I need to use TrackViewState?
    >
    > I know these could be all very simple questions to answer, but they
    > aren't for me! :-(
    >
    > Please help! What would be really useful would be just a short example
    > in C# showing how it's done. I find that the best way to understand.
    >
    > Thank you in advance,
    >
    > Mark (in dire need) Bateman...
     
    Lostinet.Web Support, Jan 7, 2004
    #3
    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. Ben Rush
    Replies:
    2
    Views:
    574
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,696
    heislord5
    May 11, 2011
  3. Doug Poland
    Replies:
    9
    Views:
    763
    VisionSet
    Sep 27, 2003
  4. mutex
    Replies:
    0
    Views:
    230
    mutex
    Jul 27, 2003
  5. Patrick Wilby via .NET 247

    Maintaining viewstate in Collections

    Patrick Wilby via .NET 247, Apr 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    147
    Patrick Wilby via .NET 247
    Apr 23, 2004
Loading...

Share This Page