Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Parent Page ViewState from the user control?

Tags:

asp.net

is there any way to access parent page ViewState from the user control.

like image 296
Thomas Avatar asked Apr 20 '11 08:04

Thomas


1 Answers

Yes you can ... To do so you just need to follow a basic trick ..

First inherit the caller page by a base page (using a base page over the project always a good practice it help later very much) like 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
}
like image 108
Moumit Avatar answered Sep 28 '22 05:09

Moumit