Is ViwState Page-Specific or UserControl-Specific

Discussion in 'ASP .Net' started by =?Utf-8?B?SmF2?=, Aug 16, 2006.

  1. ASP.Net 2.0 - using ObjectDataSources (Csla)

    I sometimes have multiple Views (or Wizards) on a Page. Some of these may
    have UserControls with Addresses or Phones in GridViews belonging to
    different entities on the Page. My "entities" are stored in the Session
    state. I save the Entity_id(Guid) of the entity whose addresses or phones
    are in the GridView on the User Control in the ViewState using:
    ViewState(Me.ID & "EntityID") = Entity_Id.toString (Me refers to the
    UserControl)
    This is done when the GridView is initially populated.

    When the user moves from one Wizard page to another (or one View to
    another), I retrieve the correct PhoneCollection or AddressCollection from
    the Session based on the Entity_id which I retrieve from the ViewState using
    CType(ViewState(Me.ID & "EntityID"), String)

    It seems to work. However, 2 questions (concerns) linger on.
    1. Do I even need to append Me.ID to Entity_ID since walking thru the
    debugger, I am seeing that the 'ViewState' is specific to each User Control.
    Is that a correct assumption?
    2. If not, then Me.ID may not distinguish an Address UC on one View from one
    on another View.

    I would appreciate a suggestion or two.

    Jav
     
    =?Utf-8?B?SmF2?=, Aug 16, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?SmF2?=

    Teemu Keiski Guest

    Hi,

    every control has its own ViewState collection (instance of
    System.Web.UI.StateBag) and essentially Page has its own also. Therefore,
    you don't need to append the me.ID to EntityID when accessing ViewState
    collection in a control.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    "Jav" <> wrote in message
    news:D...
    > ASP.Net 2.0 - using ObjectDataSources (Csla)
    >
    > I sometimes have multiple Views (or Wizards) on a Page. Some of these may
    > have UserControls with Addresses or Phones in GridViews belonging to
    > different entities on the Page. My "entities" are stored in the Session
    > state. I save the Entity_id(Guid) of the entity whose addresses or phones
    > are in the GridView on the User Control in the ViewState using:
    > ViewState(Me.ID & "EntityID") = Entity_Id.toString (Me refers to the
    > UserControl)
    > This is done when the GridView is initially populated.
    >
    > When the user moves from one Wizard page to another (or one View to
    > another), I retrieve the correct PhoneCollection or AddressCollection from
    > the Session based on the Entity_id which I retrieve from the ViewState
    > using
    > CType(ViewState(Me.ID & "EntityID"), String)
    >
    > It seems to work. However, 2 questions (concerns) linger on.
    > 1. Do I even need to append Me.ID to Entity_ID since walking thru the
    > debugger, I am seeing that the 'ViewState' is specific to each User
    > Control.
    > Is that a correct assumption?
    > 2. If not, then Me.ID may not distinguish an Address UC on one View from
    > one
    > on another View.
    >
    > I would appreciate a suggestion or two.
    >
    > Jav
    >
     
    Teemu Keiski, Aug 16, 2006
    #2
    1. Advertising

  3. Thanks Teemu
    Jav

    "Teemu Keiski" wrote:

    > Hi,
    >
    > every control has its own ViewState collection (instance of
    > System.Web.UI.StateBag) and essentially Page has its own also. Therefore,
    > you don't need to append the me.ID to EntityID when accessing ViewState
    > collection in a control.
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    > "Jav" <> wrote in message
    > news:D...
    > > ASP.Net 2.0 - using ObjectDataSources (Csla)
    > >
    > > I sometimes have multiple Views (or Wizards) on a Page. Some of these may
    > > have UserControls with Addresses or Phones in GridViews belonging to
    > > different entities on the Page. My "entities" are stored in the Session
    > > state. I save the Entity_id(Guid) of the entity whose addresses or phones
    > > are in the GridView on the User Control in the ViewState using:
    > > ViewState(Me.ID & "EntityID") = Entity_Id.toString (Me refers to the
    > > UserControl)
    > > This is done when the GridView is initially populated.
    > >
    > > When the user moves from one Wizard page to another (or one View to
    > > another), I retrieve the correct PhoneCollection or AddressCollection from
    > > the Session based on the Entity_id which I retrieve from the ViewState
    > > using
    > > CType(ViewState(Me.ID & "EntityID"), String)
    > >
    > > It seems to work. However, 2 questions (concerns) linger on.
    > > 1. Do I even need to append Me.ID to Entity_ID since walking thru the
    > > debugger, I am seeing that the 'ViewState' is specific to each User
    > > Control.
    > > Is that a correct assumption?
    > > 2. If not, then Me.ID may not distinguish an Address UC on one View from
    > > one
    > > on another View.
    > >
    > > I would appreciate a suggestion or two.
    > >
    > > Jav
    > >

    >
    >
    >
     
    =?Utf-8?B?SmF2?=, Aug 16, 2006
    #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. huobazi
    Replies:
    1
    Views:
    699
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    424
    Rajesh Tiwari
    Aug 12, 2003
  3. moid
    Replies:
    1
    Views:
    370
    Teemu Keiski
    Jan 26, 2004
  4. nail
    Replies:
    0
    Views:
    1,550
  5. Phl
    Replies:
    2
    Views:
    533
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
Loading...

Share This Page