ASP.NET-访问内容页面的母版页元素 [英] ASP.NET - Accessing Master Page elements form the Content Page
问题描述
可以从内容页面访问母版页的元素吗?
Can the elements of the Master Page be accessed from the Content Page?
假设我有从MasterPage1继承的MasterPage1和ContentPage1,并且MasterPage1有一个按钮:Button1.
Lets say I have MasterPage1 and ContentPage1 that inherits from the MasterPage1, and the MasterPage1 has a button: Button1.
我可以从内容页面更改该按钮的属性,例如使Button1不可见,不活动等吗?我该怎么做?
Can I change the property of that button from the content page, for example to make Button1 invisible, inactive etc? How can I accomplish this?
我正在使用.net2.0
I am using .net2.0
推荐答案
您必须在页面/用户控件标记中放置对MasterPage的引用.
You have to put a reference to the MasterPage in your page/user control markup.
<%@ Reference VirtualPath="..." %>
然后,在后面的代码中,只需将Page.MasterPage转换为MasterPage并访问其属性.
Then in the code-behind, you just cast the Page.MasterPage to your MasterPage and access its properties.
MyMasterPage myMasterPage = (MyMasterPage)Page.Master;
这篇关于ASP.NET-访问内容页面的母版页元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!