Is ViwState Page-Specific or UserControl-Specific

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
Thanks Teemu
Jav

Teemu Keiski said:
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
 
Back
Top