禁用用户控件的母版页的负荷 [英] disable usercontrol on the load of master page

查看:139
本文介绍了禁用用户控件的母版页的负荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的某些页面上的母版页。和母版页加载用户的控制。所以我想禁用或启用具有母版页一些页面加载用户控件。

I am using master page on some pages. And that master page is loading the user control. So I want to disable or enable user control on some page load which has master page.

反正我的母版页的Page_Load()

Is there anyway can I disable User control on master page Page_load()

<div class="ucTabCtrl" >
    <uc1:TLTabControl ID="ctrlname" runat="server" Visible="False" />
</div>

Master Page_load()
{
 // checking some condition if true
 ctrlname.visible = true;
}

但问题是我不能够得到用户CTRL实例,总之ctrlname为空所有的时间。

but the problem is I'm not able to get the instance of user ctrl, in short ctrlname is null all the time.

推荐答案

您的问题是有点难以理解,但我认为你在找什么是这样的:

Your question is kinda hard to understand, but i think what you are looking for is something like this:

public partial class Site1 : System.Web.UI.MasterPage
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (Page is WebForm1 || Page is WebForm2)
		{
			webUserControl11.Visible = false;
		}
	}
}

另外,您可以实施,表明这种行为的页面的接口。沿着线的东西:

Alternatively you could implement an interface on the pages that indicates this behavior. Something along the lines:

public partial class Site1 : System.Web.UI.MasterPage
{
	protected void Page_Load(object sender, EventArgs e)
	{
		ISpecialPage specialPage = Page as ISpecialPage;

		if (specialPage != null && specialPage.ShouldDisableUserControl)
			webUserControl11.Visible = false;
	}
}

public interface ISpecialPage
{
	bool ShouldDisableUserControl { get; }
}

这篇关于禁用用户控件的母版页的负荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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