ASP.NET-访问内容页面的母版页元素 [英] ASP.NET - Accessing Master Page elements form the Content Page

查看:142
本文介绍了ASP.NET-访问内容页面的母版页元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以从内容页面访问母版页的元素吗?

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屋!

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