在登陆界面输入信息后,不跳转界面,也不出现bug,为什么?  以下是login.aspx.cs代码  protected void ButtonLogin_Click(object sender, EventArgs e)
    {
        string sqlConnectStr = ConfigurationManager.ConnectionStrings["ExamConnectionString"].ConnectionString;
        //创建数据库连接,并打开
        SqlConnection con = new SqlConnection(sqlConnectStr);
        con.Open();
        string sqlStr;
        if (DropDownListIdentity.SelectedItem.Text == "学生")
            sqlStr = "select SNo,SPass from [student]";
        else
            sqlStr = "select TNo,TPass from [teacher]";
        SqlCommand com = new SqlCommand(sqlStr, con);
        SqlDataReader reader = com.ExecuteReader();
        reader.Read();
        //前台后台登陆
        if (DropDownListIdentity.SelectedItem.Text == "学生")
        {
            if ((TextBoxUserName.Text == reader["SNo"].ToString())
            && (TextBoxPass.Text == reader["SPass"].ToString()))
            {
                Session["Identity"] = "学生";
                reader.Close();
                con.Close();
                Response.Redirect("~/Default.aspx");
            }
            else Response.Write("<script>alert('用户名或密码错误!')</script>");
        }
        else if (DropDownListIdentity.SelectedItem.Text == "教师")
        {
            if ((TextBoxUserName.Text == reader["TNo"].ToString())
                 && (TextBoxPass.Text == reader["TPass"].ToString()))
            {
                Session["Identity"] = "教师";
                reader.Close();
                con.Close();
                Response.Redirect("~/BackMain.aspx");
            }
            else Response.Write("<script>alert('用户名或密码错误!')</script>");
        }
    }
}

解决方案 »

  1.   

    搞定了,是因为在dropdownlist中属性 学生中加了空格,导致后面没法识别。
    谢啦
      

  2.   

    成功是直接跳转了,而且你也没有写成功的alert至于失败的情况,window.onload=function(){
             alert(‘失败’);
    }代替你的alert
    还有就是不要使用response.write来注册客户端js,这样会导致你的页面的样式出现混乱。而是改用clientsript.registescript.............
      

  3.   


    TextBoxUserName.Text == reader["SNo"].ToString()你的数据库里就一个学生?