• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

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

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
Samm1502
Asked:
Samm1502
1 Solution
 
carlnorrbomCommented:
Hi,

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

/Carl.
0
 
tetorvikCommented:
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
 
Samm1502Author Commented:
That makes sense.  Thanks
Sam
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now