从母版页调用的内容页类方法 [英] content page class method calling from master page class

查看:89
本文介绍了从母版页调用的内容页类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的内容页面类中有一个公共方法,我想从母版页类中调用此方法
谢谢

I have a public method in my content page class, I want to call this method from master page class
Thanks

推荐答案

您可以从基类继承页面.然后,您可以在基类中创建一个虚拟方法,该方法将在您的页面中被覆盖.然后,您可以像这样从主页上调用该虚拟方法-

You can inherit your page from a base class. Then you can create a virtual method in your base class which will get overridden in your page. You can then call that virtual method from the master page like this -

(cphPage.Page as PageBase).YourMethod();

在这里, cphPage 是母版页中 ContentPlaceHolder 的ID. PageBase 是包含 YourMethod 方法的基类.

Here, cphPage is the ID of the ContentPlaceHolder in your master page. PageBase is the base class containing the YourMethod method.

当然,在使用页面实例调用 YourMethod 方法之前,您必须进行空检查.

Of course, you'll have to put a null checking before you call the YourMethod method using the page's instance.

这篇关于从母版页调用的内容页类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆