如何控制从子页面asp.net母版页上的元素 [英] How to control elements on a asp.net master page from child page
本文介绍了如何控制从子页面asp.net母版页上的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的asp.net网站上几页,我想关闭母版页上的控件。有没有从子页面与母版页,以交流的方式?
I have a few pages on my asp.net website that I would like to turn off a control on the master page. Is there a way to communicate with the master page from a child page?
推荐答案
最简单的方法是设置你的母版页上的属性调用时处理该开/关功能。然后在你的子页面设置指令的MasterType 得到一个强类型引用您的母版页绕过需要转换。
Easiest way is to setup a property on your master page that handles the on/off functionality when called. Then in your child page set the MasterType directive to get a strongly typed reference to your master page to bypass the need to cast.
您的孩子页面将有:
<%@ MasterType VirtualPath="~/Site1.Master" %>
和调用母版页的属性:
Master.MyLabel = false; // or true
因此,对你的主人,你可以有:
So on your master you could have:
public bool MyLabel
{
get
{
return masterLabel.Enabled;
}
set
{
masterLabel.Enabled = value;
}
}
这篇关于如何控制从子页面asp.net母版页上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文