黑马程序员技术交流社区
标题:
有关ASP.NET内置对象的问题
[打印本页]
作者:
迷你卡卡
时间:
2013-9-29 15:32
标题:
有关ASP.NET内置对象的问题
本帖最后由 迷你卡卡 于 2013-9-30 14:26 编辑
<form id="form1" runat="server">
<div>
用户名:<asp:TextBox ID="txtUsertype" runat="server"></asp:TextBox><br />
密 码:<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox><br />
<asp:Button ID="btnLogin" runat="server" Text="登陆" />
</div>
</form>
这是一个简单的登陆界面,
protected void Button1_Click(object sender, EventArgs e)
{
string usertype = txtUsertype.Text.Trim();
Session["UserType"] = GetUsertype(usertype);
Application.Lock();
switch (Session["UserType"].ToString())
{
case "1":
Application["admin"] = Convert.ToInt32(Application["admin"]) + 1;
break;
case "2":
Application["user"] = Convert.ToInt32(Application["user"]) + 1;
break;
case "3":
Response.Write("<script>alert('非法账户,不能登陆')</script>");
break;
}
Application.UnLock();
Response.Redirect("count.aspx?=usertype" + usertype);
}
private static int GetUsertype(string str)
{
if (str=="admin")
{
return 1;
}
if (str=="user")
{
return 2;
}
else
{
return 3;
}
}
这是他的后台代码,
protected void Page_Load(object sender, EventArgs e)
{
string usertypeCount = Request.QueryString["usertype"].ToString();
if (Application["admin"]!=null)
{
Response.Write("<br/>管理员的访问量为" + Application["admin"]);
}
else
{
Response.Write("管理员的访问量为:0");
}
if (Application["user"]!=null)
{
Response.Write("<br/>用户的访问量为" + Application["user"]);
}
else
{
Response.Write("用户的访问量为:0");
}
}
这是另外一个叫count.aspx页面的后台代码
为什么Button1_Click事件之后就报异常了呢?
求各位大神指导,在线等待中......
作者:
追梦无悔
时间:
2013-9-30 00:38
可以详细的说明一下是什么异常吗?
作者:
曹伟
时间:
2013-9-30 09:09
我发现两个问题:
1."登陆"的那个按钮都没有加上 OnClick="Button1_Click" 的事件啊
2.跳转时传递参数错误
Response.Redirect("count.aspx?=usertype" + usertype);
改为
Response.Redirect("count.aspx?usertype=" + usertype);
作者:
迷你卡卡
时间:
2013-9-30 14:26
曹伟 发表于 2013-9-30 09:09
我发现两个问题:
1."登陆"的那个按钮都没有加上 OnClick="Button1_Click" 的事件啊
2.跳转时传递参数错 ...
额 多谢了呢 还真是,原来越是细小的问题越不容易被发现
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2