从内容页调用母版页中的函数?

Call function in master page from content page?

我在母版页中有一个功能。
我想从内容页面调用这个函数。
我的内容页是从嵌套的母版页创建的,该功能位于主母版页中。我的母版页位于名为 "masters".
的文件夹中 我该怎么做?

Page.Master 转换为您的主人的实际类型。然后你就可以调用那个方法了:

var master = this.Master as MyMaster;
if(master != null)
  master.MethodName();

如果您的页面位于 MasterPage 中,并且有另一个 MasterPage 提到:

var mainMaster = master.Master as MyMainMaster;
if(mainMaster != null)
   mainMaster.MethodName();

制作母版页方法public并像这样使用

((Site1)this.Master).Page_Load(sender, e);

其中 Site1 是您的主页 class。