Access parent viewstate page from user control?

Is there a way to access the parent ViewState page from a user control.

+4
source share
3 answers

The ViewState property of the Page protected class. Therefore, there is no way to access it from a user control unless you want to break the encapsulation using reflection .

+4
source

Yes you can ... To do this, you just need to follow basic trick ..

First inherit the calling page using the base page (using the project’s base page is always a good practice it will help later), as shown below ...

 public abstract class BasePage : Page { public StateBag ViewState { get { return base.ViewState; } } } 

Later you can call this property from usercontrol ........

 var CallerPage = this.Page as BasePage; if (CallerPage!=null) { var CallerPageViewState = CallerPage.ViewState; //Do your rest job } 
+6
source

In a word, no. Depending on what you want to do, although there may be another way to do what you are trying to achieve.

More information on what you want to achieve will help people more accurately answer your question.

0
source

All Articles