tags:

views:

30

answers:

2

I have 2 instances of a user control (ascx) in a view page.

I set ViewData["xyz"] = "True" inside the user control.

The first instance would set ViewData["xyz"] to "True". However, this same value is not retained in the second instance of the user control.

I was expecting ViewData["xyz"] to be still "True", but it is null.

Please help.

What is the best way to have a shared variables across the user controls?

+3  A: 

Any logic should be done within controller. User controls (Views, Partial Views) shouldn't have logic that requires put data to ViewData collection. Views are only for presentation.

dario-g
A: 

Perhaps you can do ((ViewPage)Page).ViewData["whatever"] = "value";

A better idea is probably to not require shared state between the user controls,

erikkallen