设置母版页属性 [英] Setting Master page properties

查看:69
本文介绍了设置母版页属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我创建了一个母版页,其中有两个选项卡,一个用于首页,另一个用于信息(称为关于").默认情况下,显示主页.他们是母版页中用于登录的链接,该链接将用户带到登录页.它不是.Net框架的通用登录控件.在主页上,有诸如登录标签"(指向登录页面的链接),登录名"(登录者的姓名)和退出"链接之类的控件.
第一次注销时,登录名不可见.用户登录后,这两个控件将可见,而登录控件则隐藏.成功登录后,我将定向至About.aspx页面,在该页面中,我编写了代码以使这些控件可见.但是,当我单击主页链接时,它们将变得不可见,并且登录控件也将变为可见.
因此,我需要做的是在成功登录后隐藏登录链接按钮,并隐藏登录名和注销链接按钮以使其可见.
但是在整个应用程序中应该保持一致.当我在About.aspx页面上编写了代码时,它仅适用于该页面,为什么不适用于其他页面?它是母版页n内容页生命周期事件吗?还是我需要将该代码作为函数并在包含该母版页的应用程序中的每个其他页上运行它?

预先感谢.

Hi all,
I''ve created a master page having two tabs one for home and other on for info(called About). By default Home page is shown. Their is link for login in master page which takes user to login page. Its not generic login control of .Net framework. On master page there are controls like Login label(ref link to login page), Login name(name of who logged in) and log out link.
At first log out and login name is not visible. Once user logs in these 2 controls would be visible and login control hidden. On successful login i am directing to About.aspx page where i''ve written the code to make these control visible. But when i click on the home link of they become invisible and Login control becomes visible.
So what i need to do is i need to hide login link button on successful login and login name and logout link button to make visible.
But it should be consistent throughout the application. As i''ve written the code on About.aspx page it is working for that page only why not for other pages? Is it master page n content page life cycle events? Or I need to make that code as function and run it for every other page in the application containing that master page?

Thanks in advance.

推荐答案

嘿,
控制这种情况的一种方法是(如果我正确理解了这个问题)使会话变量可变.当用户成功登录时,将用户的ID传递给会话.并在每个页面的Load事件上将控件的属性设置为隐藏.

例如
hey,
one way to control this scenario is (if i have understod the question correctly) that make a session variable. when the user logs in successfully pass the ID of the user to the session. and on the Load event of each page set the propoerty of the controls to hidden.

e.g.
if(SuccessfullLogin)
{
Session["LoggedInUserID"]=ID;
}
else
{
Session["LoggedInUserID]="";
}


然后在每个页面的Load事件上


then on the Load event of each page

if(String.IsNullorEmpty(Session["LoggedInUserID"].ToString()))
{
Label objLabel =(Label)Master.FindControl("LabelLogin");
objLabel.Visible=True;
}
else
{
Label objLabel =(Label)Master.FindControl("LabelLogin");
objLabel.Visible=False;
}



希望它能给你这个主意.
祝你好运
Ahsan Sarfraz



Hope it will give you the idea.
Best of luck
Ahsan Sarfraz


一种实现此目的的方法是这样的:

在母版页中定义了属性或函数.在子页中,您编写如下内容

One way of acheiving this is like this:

Have the property or function defined in master page.In your child page,you write as below

<%@ MasterType VirtualPath="~/Site1.Master" %> 

要从子页面调用母版页的属性/功能,请执行以下操作

And to call the property/function of the master page,from child pages do as below

Master.Property or Master.Function()


这篇关于设置母版页属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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