如何创建页面实例

时间:2022-06-07 18:09:53

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.

我有一个接口IPageState,它有一个方法ClearState。我想创建一个asp.net页面的实例,它实现了这个接口,并在该实例上调用ClearState方法。

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

任何人都可以帮助我如何创建一个asp.net页面的实例。

3 个解决方案

#1


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

它与创建任何其他对象的实例没什么不同。

#2


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()
    {

    }
}

#3


Let me elaborate with and example,

让我详细说明一下,

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

ProducuListing.aspx和ProductDetails.aspx是我网站上的两个页面。我想做点什么

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.

在ProductListing.aspx页面中,反之亦然。现在我不能像上面的例子那样硬编码页面类名。因此,我将使用的显而易见的解决方案是反思。但是当我使用vs 2005网站项目时,每个页面的程序集都不同。

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.

我想要一个通用的解决方案,我可以在网站中创建任何页面的实例,并检查它是否实现了该接口,以及是否在其上调用了ClearState方法。

I hope this makes my question more clear.

我希望这使我的问题更清楚。

Counting on you folks!!!!

指望你的人!!!!

#1


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

它与创建任何其他对象的实例没什么不同。

#2


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()
    {

    }
}

#3


Let me elaborate with and example,

让我详细说明一下,

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

ProducuListing.aspx和ProductDetails.aspx是我网站上的两个页面。我想做点什么

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.

在ProductListing.aspx页面中,反之亦然。现在我不能像上面的例子那样硬编码页面类名。因此,我将使用的显而易见的解决方案是反思。但是当我使用vs 2005网站项目时,每个页面的程序集都不同。

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.

我想要一个通用的解决方案,我可以在网站中创建任何页面的实例,并检查它是否实现了该接口,以及是否在其上调用了ClearState方法。

I hope this makes my question more clear.

我希望这使我的问题更清楚。

Counting on you folks!!!!

指望你的人!!!!