English 中文(简体)
在该网页上使用助手套法
原标题:Call a method from the helper class on the page that is calling the helper method

我有3个伙伴关系。 NET pages. 每种方法都有自己的GetSearchResult方法,产生不同的搜索结果,并填写了GridView。 每一页都用一个助手班的共享助手方法。

现在,在这个助手类别中,我想执行这一“方法,该方法属于称为助手法的网页上。

这是可能的吗? 如果是的话,我如何这样做?

最佳回答

采用“GetSearchResult”方法作为助手方法的参数。 这将使助手方法能够进入打电话者的方法。 你们需要建立一个接口来做到这一点。

public interface ISearchable
{
    void GetSearchResult();
}

public class MyPage : Page, ISearchable
{
    public void GetSearchResult() {
        HelperClass.HelperMethod(this); // Pass in
    }
}

public static class HelperClass
{
    public static void HelperMethod(ISearchable page) {
        page.GetSearchResult();
    }
}
问题回答

You could pass a reference to the page as an argument to the helper method, and call GetSearchResult again on the page. (Ideally, your page should implement an interface, say ISearchPage, that contains the method GetSearchResult)

[Edit:在我打上上述字时,David Anderson在其答复中提供了密码]

或者,根据你的助手方法,在助手的物体上设定了身份标志(或使用身份清单)。 在你的网页上,你可以读到这一旗帜或高价值,如果情况表明GetSearchResult应当重新命名,则再次叫它。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签