Is ViwState Page-Specific or UserControl-Specific

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
 
T

Teemu Keiski

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.
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top