登录后在母版页上的欢迎消息 [英] Welcome message on Master Page after login

查看:79
本文介绍了登录后在母版页上的欢迎消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户登录后,我有一个消息名称要显示在MasterPage上.现在,它仅显示 MyAccount .请查看代码,让我知道如何实现. 尝试过,但无法在母版页中进行管理.请参阅我的代码作为参考:-

I have a message name to be showed on MasterPage when the user is logged in. Right now it is showing just MyAccount. Please see the code and let me know how to achieve that. Tried but couldn't managed in the master page. Please see my code as ref:-

<div id="nav-right">
  <div class="showhide-account">
     <img src="images/user.png" width="13" height="13" alt="">&nbsp;&nbsp;My Account
  </div>
  <div class="nav-divider">|</div>
  <div id="logout">
          <a href="Login.aspx" id="logOut" runat="server">Logout</a>
   </div>
   <div class="clear">&nbsp;</div>
</div>

推荐答案

您可以执行以下操作: 这样做有两种方法:-

You can do this:- There are two way to do so:-

第一种方式:-

我认为您必须在div中添加lblusername标签.

I think you have to add lblusername lable in your div.

<div class="showhide-account">
    <img src="images/user.png" width="13" height="13" alt="">&nbsp;&nbsp;
        <asp:Label ID="lblUserName" runat="server"></asp:Label>
</div>

然后,在后面的代码中设置lblUserName的文本

Then, set the Text of lblUserName in code behind

lblUserName.Text = Session["UserName"].ToString();

第二种方式:- 新增属性

2nd Way:- Added Property

public string UserName
        {
            get
            {
                //return the object from session
                return (string)Session["UserName"];
            }

            set
            {
                Session["UserName"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
           //set UserName with UserName from Database value after username &
           //password verification 
           this.UserName = "XYZ User";
        }

,然后在.aspx页中,

and then in .aspx page,

<div class="showhide-account">
     <img src="images/user.png" width="13" height="13" 
                          alt="">&nbsp;&nbsp;<%=UserName%>
  </div>

这篇关于登录后在母版页上的欢迎消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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