如何将会话值从aspx页面传输到母版页 [英] How to transfer session values from aspx page to master page
本文介绍了如何将会话值从aspx页面传输到母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的网络应用程序中显示为欢迎并登录用户名。
I would like to display as Welcome and logged in username in my web application.
推荐答案
没什么可做的......只需指定用户名文本框值到登录页面中的Session变量并将该Session变量访问到母版页:
登录页面:
Nothing to do more....Just assign the username textbox value to the Session variable in the login page and access that Session variable to the master page:
Login page:
DataTable dt = Check username in the database and put in a datatable
if (dt != null && dt.Rows.Count > 0)
{
Session["UserName"] = txtUserName.Text.Trim();
Response.Redirect("/Home.aspx");
}
else
{
lblMsg.Text = "username or password invalid";
}
在母版页中:
In the master page:
if (Session["UserName"] != null)
lblWelcome.Text = "Welcome " + Session["UserName"].ToString();
else
lblWelcome.Text = "Welcome Guest"
请阅读我对该问题的评论。
我建议从这里开始:如何:在ASP之间传递值.NET网页 [ ^ ] + 将会话变量从ContentPage传递到MasterPage的控件 [ ^ ]。
Please read my comment to the question.
I'd suggest to start here: How to: Pass Values Between ASP.NET Web Pages[^] + passing Session variables from ContentPage to MasterPage's Control[^].
参考
http://forums.asp.net/t/1367379.aspx?Display+user+name+ in + the + header + when + logged + in [ ^ ]
这篇关于如何将会话值从aspx页面传输到母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文