Solved

Will ViewState variable with same name set in different controls overwrite same value?

Posted on 2009-05-10
3
427 Views
Last Modified: 2012-05-06
Hi there

Can anyone tell me whether ViewState["MyValue"] will refer to the same ViewState item if I set  it in different control classes i.e. lets say I have 2 user controls, Control1 and Control2 and Control1 sets this ViewState value and then Control2 also sets the same ViewState variable name are they both referencing the same item or does .NET prefix the name with the control that created it a bit like the control ClientID?

The same goes for Session variables, will different controls using the same variable name be overwriting the same value?

Many thanks
Sam
0
Comment
Question by:Samm1502
3 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24349431
Hi,

Yes, both session and viewstate are user / session specific, this means they will be overritten if referenced from multiple controls.

/Carl.
0
 
LVL 9

Accepted Solution

by:
tetorvik earned 500 total points
ID: 24349483
No viewstate is control specific (Control.ViewState is protected property). so if using the same viewstate key in multiple controls on a page they don't override each others. Similary you're not able to access page's viewstate from user control.

Session variable however will override if the same key is used.

 
0
 

Author Closing Comment

by:Samm1502
ID: 31579908
That makes sense.  Thanks
Sam
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now