在用户控件中如何使用Session
最近写了个登陆的用户控件.ascx文件利用Session保存登陆信息和判断是否显示登陆框
.ascx.cs中
Response.Write("<script language=javascript>alert('你已经成功登陆!');</script>");
Session["memberlogin"] = "OK"; //保存登陆信息到Session变量
Session["membername"] = pu;
Session["memberpass"] = pw;
Response.Redirect("index.aspx");
}
else
{
Response.Write("<script language=javascript>alert('非法登录!');</script>");
}
并且在.ascx文件中
<%
if (Session["memberlogin"]=="")
{
%>
<td>
用户名:<asp:TextBox runat="server" ID="TextBox_usertext" ></asp:TextBox>
密 码:<asp:TextBox runat="server" ID="TextBox_userpass" TextMode="Password"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" Height="20px"
ImageUrl="~/image/login.jpg" Width="60px" OnClick="ImageButton1_Click" />
<asp:ImageButton ID="ImageButton2"
runat="server" Height="20px" ImageUrl="~/image/exit.jpg" Width="60px" OnClick="ImageButton2_Click"/>
</td>
<%
}
else
{
%>
为什么出现错误提示说,当前上下文中缺少Session
麻烦高手帮忙解决下……在线等待