Hi,
In Asp.net 2.0 if we want to create the object of another page (in the same application) then we can not do it. We get a compiler error in this case. The reason is that each page is compiled into an assembly (We can also make the directory to be compiled in the same assembly). Hence the two pages might not be in the same assembly. And hence we are not able to create the object of another page in the same web application in another page (As they will not be in the same assembly).
But many a times we want to create the object of another page in the code behind class. I know we can use a base page (will be kept in App_Code folder) for all class and derive all the pages from that class. Now we can create the object of the page by typecasting the base page. But this will not solve the entire problem. As we will not have all the methods of the individual class.
To refer another page in Asp.net 2.0 we have to use the @reference tag in the page. We can use the tag to refer any page or class. In fact we can refer anything by giving the virtual path of the same. The @reference get the user control, Page or arbitrary file (given by virtual Path) to be dynamically compiled against the current Asp.Net file.
When we refer a page with the help of the @Reference tag, we can create the object of the page in the code behind. The basic syntax of the tag is simple.
<%@ Reference Page="~/Default.aspx" %>
The page has 3 attributes which are explained below.
Page - The path to the external page that will be dynamically compiled with this page.
Control – The path to the external user control that will be linked with the paged and dynamically compile and link to the current file.
VirtualPath – The virtual path for the reference. This can be any file type as long as they have a build provider. This means that we can point to a master page here.
Vikram