tags:

views:

206

answers:

3

I have an interface IPageState which has a method ClearState. I want to create an instance of an asp.net page which implements this interface and call the ClearState method on that instance.

Can anyone help me as to how to create the instance of an asp.net page.

+1  A: 

It's really no different than creating an instance of any other object.

Chris Lively
+1  A: 

I am not sure I understand the question. A page class is the same as any other class. Ex:

Public Class ExamplePage : IPageState
{
    private void ClearState()
    {

    }
}
Jim Petkus
A: 

Let me elaborate with and example,

ProducuListing.aspx and ProductDetails.aspx are two pages in my website. I want to do something like

IPageState pd = new ProductDetails() as IPageState;
pd.ClearState();

in the ProductListing.aspx page and vice versa. Now I cannot hard code the page class names like in the above example. So the obvious solution which I would use is reflection. But then the assemblies for each page is different as I am using the vs 2005 website project.

I want a generic solution wherein I can create an instance of any page in the website and check if it implements that interface and if it does call the ClearState method on it.

I hope this makes my question more clear.

Counting on you folks!!!!

Hemanshu Bhojak
Just so you know: you can edit your question and add the example there instead.
Spoike
I don't understand the point of this. What is the point of clearing the state (or calling any method, for that matter) on a page instance that no user has requested? It sounds to me like your ProductDetails page might be doing stuff that should reside in a separate class.
Helen Toomik
I use session to store some page specific data which i want to clear when the user leaves the page so that the memory is freed asap. For this reason i want to call the clear method on the previous page which will clear the data which that page has stored in session.
Hemanshu Bhojak