Wednesday, May 25, 2005

Accessing Parent form Properties in Another ASPX form using Context.Handler.

If you have some properties in a Web form and you need then in another from that is transferred using Server.Transfer method.

This is helful by not using session variables or Query strings.

Create a property in the Parent Web form.
Add this line below the @ directive on the target page.

<% Reference Page="Parentpage.aspx" %>

Now in the code behind of the child page, declare a varaible of type Parentpage.

Private PG Parentpage.

A reference to the parentpage can be obtained using the Context.Handler property like this.
PG = (WebForm3)Context.Handler;

all public properties and methods of Parentpage can be accessed by PG.

No comments: