Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-05-10
3
Medium Priority
?
468 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 2000 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

Technology Partners: 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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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