Solved

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

Posted on 2009-05-10
3
434 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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