It is said that is Page specific; that means, it is available only on the same page on which it was created. Once you redirect to another page, the previous page's is no longer accessible. But that is not true.
Yes, we can access the variables across pages. This is only possible if or is used to redirect the user to other page. If is used, then cannot be accessed across pages.
I have created two pages named:
1) : This page sets the variable and transfers the user to another page using .
2) : This page accesses the variable of page.
This is the code of page:
This page also contains a method which actually returns the of this page to the calling function. The return type of the method is class.
class: This class is the primary storage mechanism for all HTML and Web server controls. It stores attribute/value pairs as s associated with the control. It tracks changes to these attributes only after the method is executed for a page request, and saves the changes to the page's or control's .
Now let's take look at code:
Whenever we use or , We can get the previous page object via property. Using Previous Page, we can find the controls of the previous page. For example, one can access control placed in Page in current Page.
Looking at the code, I have created a property in this page, which returns the previous page's . It first checks whether is or not, if it's not , then it creates an object of the previous page. Now using , we can invoke the method of the previous class. Using class, I have invoked the method of .
In event, I am able to access the variable of . We can access all the variables set in .