A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 迷你卡卡 中级黑马   /  2013-9-29 15:32  /  1930 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 迷你卡卡 于 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事件之后就报异常了呢?
求各位大神指导,在线等待中......

评分

参与人数 1技术分 +1 收起 理由
haxyek + 1

查看全部评分

3 个回复

倒序浏览
可以详细的说明一下是什么异常吗?
回复 使用道具 举报
我发现两个问题:
1."登陆"的那个按钮都没有加上  OnClick="Button1_Click"   的事件啊
2.跳转时传递参数错误
Response.Redirect("count.aspx?=usertype" + usertype);
改为
Response.Redirect("count.aspx?usertype=" + usertype);

评分

参与人数 1技术分 +1 收起 理由
haxyek + 1

查看全部评分

回复 使用道具 举报
曹伟 发表于 2013-9-30 09:09
我发现两个问题:
1."登陆"的那个按钮都没有加上  OnClick="Button1_Click"   的事件啊
2.跳转时传递参数错 ...

额  多谢了呢   还真是,原来越是细小的问题越不容易被发现
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马