访问母版页控制ASCX文件 [英] Accessing Master page control in ascx file
问题描述
我有一个包含了2面板控制2菜单的母版页文件。
我也用一个控制检查,如果用户登录,并得到用户的类型。
I have a master page file that contains a 2 menu's in a 2 panel controls. I also use a control to check if user is logged in and get the type of user.
Deppending上我想说明的类型/隐藏面板。控制本身并不在主网页,但通过动态CMS系统引用。
Deppending on the type I want to show / hide the panel. The control itself is not referenced in the master page but dynamically through the CMS System.
我想使用的FindControl用户控件查找母版页面板控制。我曾尝试不同的方法,但所有的回来跟空。
I want to use findcontrol in the user control to find the panel control in the master page. I have tried different methods but all come back with null.
在母版页内容占位符
ASP:内容=服务器ContentPlaceHolderID =PHMainBlock
The content placeholder in the master page is asp:Content runat="server" ContentPlaceHolderID="PHMainBlock"
和控制被称为
ASP:面板ID =NormalUser=服务器
and the control is called asp:Panel ID="NormalUser" runat="server"
我已经使用code试图....
I have tried using the code....
Panel ph = (Panel)Page.Master.FindControl("NormalUser");
ph.Visible = false;
但带回空,任何帮助?
but brings back null, any help?
感谢..
推荐答案
您可以在您创建一个公共财产母版页即
You could create a public property in you Master Page i.e
public bool ShowPanel
{
set
{
NormalUser.Visible = value;
}
}
和称呼它
if (Page.Master is NameOfMasterPage)
{
((NameOfMasterPage)Page.Master).ShowPanel = false;
}
这篇关于访问母版页控制ASCX文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!