时间:2021-07-01 10:21:17 帮助过:8人阅读
<!--登录小div-->
<div class="loginDiv">
<div class="LoginDivTitle">
会员登录
</div>
<table class="loginTable">
<tr>
<td class="LoginLabel">用户名:</td>
<td><input type="text" class="loginTxt" id="txtUserName" /></td>
</tr>
<tr>
<td class="LoginLabel">密码:</td>
<td><input type="password" class="loginTxt" id="txtPass" /></td>
</tr>
<tr>
<td class="LoginTdButtons" colspan="2">
<input src="../images/az-login-gold-3d.gif" type="image" id="btnLogin" />
<input src="../images/az-newuser-gold-3d.gif" type="image" id="btnReg" />
</td>
</tr>
</table>
</div>
<div class="loginOkDiv" style="display:none">
<span class="spanLoginOk" id="spanUserInfo">
尊敬的<%=serverUserName %>,欢迎你光临!
</span>
</div>
<1>.在后台Main.master中的代码
代码如下:
protected string serverUserName;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Model.Users user = Session["currUser"] as Model.Users;
if (user != null)
{
serverUserName = user.Name;
}
}
}
<2>MainPage主页面中后台代码,它是继承于模板页Main.master的
代码如下:
public partial class MainPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Model.Users user = Session["currUser"] as Model.Users;
if (user != null)
{
common.CommonCode.ExecuteScriptFunc(this,true);
}
else
{
common.CommonCode.ExecuteScriptFunc(this,false);
}
}
}
}
<3>ExecuteScriptFunc封装代码
代码如下:
public static void ExecuteScriptFunc(System.Web.UI.Page page, bool bShowUserInfo)
{
string func = "function showUser(isLogin){\r\n\r\nif (isLogin) {\r\n" +
"$(\".loginDiv\").hide();\r\n" +
"$(\".loginOkDiv\").show();\r\n" +
"}\r\n" +
"else {\r\n" +
"$(\".loginDiv\").show();\r\n" +
"$(\".loginOkDiv\").hide();\r\n" +
"}}";
string func1 = "";
if (bShowUserInfo)
{
func1 = func + "\r\n" +
"$(function(){\r\nshowUser(true)" +
"});";
}
else
{
func1 = func + "\r\n" +
"$(function(){\r\nshowUser(false)" +
"});";
}
page.ClientScript.RegisterStartupScript(page.GetType(), Guid.NewGuid().ToString(),
func1, true);
//page.ClientScript.RegisterStartupScript(page.GetType(), Guid.NewGuid().ToString(),
// func1);
}