调用方法在母版页 [英] Call Method in Master Page

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

问题描述

我在我的asp.net母版页的公共方法。是否有可能从内容页面调用这个,如果是哪些步骤/语法?

I have a public method in my asp.net Master Page. Is it possible to call this from a content page and if so what are the steps/syntax?

推荐答案

从在,就可以把页面为特定类型(你自己的法师类型暴露所需的功能),使用来一边踩任何异常的类型不匹配:

From within the Page you can cast the Master page to a specific type (the type of your own Master that exposes the desired functionality), using as to side step any exceptions on type mismatches:

var master = Master as MyMasterPage;
if (master != null)
{
    master.Method();
}

在上面的code,如果的类型是不是 MyMasterPage 然后,没有方法的调用将尝试;否则会被称为预期。

In the above code, if Master is not of type MyMasterPage then master will be null and no method call will be attempted; otherwise it will be called as expected.

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

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