当条件存在时,动态地将主页面添加到现有页面 [英] Adding Master Page to an existing Page dynamically when a condition existis
问题描述
您好,
我已经创建了一个网页,现在我想添加母版页,问题是我只需要在显示母版页时用户输入,如果管理员进入母版页应该被禁用,它应该显示页面
Hello,
I have created a web page, now i want to add the master page, the problem is i only have to show the master page when the user enters and if the administrator enters the master page should be disabled and it should show the page as it is
void Page_PreInit(Object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
if (Session["login"].ToString() != "admin")
{
this.MasterPageFile = "~/NewMaster.master";
}
}
}
catch (Exception ex)
{
lable1.text = ex.ToString();
}
}
i也试过这个.Page.MasterPageFile =〜/ NewMaster.master;
它不起作用。
请帮助
谢谢
i also tried this.Page.MasterPageFile = "~/NewMaster.master";
it is not working.
please help
thank you
推荐答案
然后我将不得不创建两个母版页
i只需要一个母版页和一个aspx页
aspx页面应该正常工作管理员的主页面
但是应该为用户添加母版页
then i will have to create two master page
i just want one master page and one aspx page
the aspx page should work normally without master page for admin
but should add master page for user
好的,但你不能用一个 aspx
。
您可以做的是,将所有控件放在 UserControl
中并将其包含在<$ c中$ c> aspx 页面。
现在您不需要在两个页面中重复它们,也可以在将来使用它。
Okay, but you can't do it with one aspx
.
What you can do is, put all the controls in a UserControl
and include that to both the aspx
page.
Now you don't need to repeat them in both the pages and it can also be used in future.
这篇关于当条件存在时,动态地将主页面添加到现有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!