Solved

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

Posted on 2009-05-10
3
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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