protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection sqlconn = null;
        SqlCommand sqlcmd = null;
        try
        {
            if (!string.IsNullOrEmpty(txtUserName.Text.Trim()) && !string.IsNullOrEmpty(txtPassword.Text.Trim()))
            {
                string sqluserdata;
                sqluserdata = @"SELECT
                          A.[loginid]
                          ,A.[password] 
                          ,A.[registertime]
                          ,A.[registeruser]
                          ,A.[updatetime]
                          ,A.[updateuser]
                          ,A.[status]
                          ,A.[delflg]
                         
                      FROM [OperatorInfo] A 
                      WHERE 1 = 1 ";                sqluserdata += " AND A.[loginid] = @userloginId AND A.[password] = @passordword AND A.status = '1' AND A.delflg = '0' ";                sqlconn = new SqlConnection(ConnectionString);
                if (sqlconn.State == System.Data.ConnectionState.Closed)
                {
                    sqlconn.Open();
                }
                string encodePassword = txtPassword.Text;
                DataTable dtUser = new DataTable();
                sqlcmd = new SqlCommand(sqluserdata, sqlconn);
                sqlcmd.Parameters.Add(new SqlParameter("@userloginId", SqlDbType.VarChar, 20) { Value = txtUserName.Text });
                sqlcmd.Parameters.Add(new SqlParameter("@passordword", SqlDbType.VarChar, 150) { Value =_3DesUtil.Des3EncodeECB(encodePassword) });
                SqlDataAdapter sqa = new SqlDataAdapter(sqlcmd);
                sqa.Fill(dtUser);              
                if (dtUser.Rows.Count == 0)
                {
                    Response.Redirect("error.aspx?ex=0", false);
                }
              
                else if (dtUser.Rows.Count == 1)
                {
                    FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
                }
                
                else
                {
                    Response.Redirect("error.aspx?ex=1", false);
                }
            }
            else if (string.IsNullOrEmpty(txtUserName.Text.Trim()) && string.IsNullOrEmpty(txtPassword.Text.Trim()))
            {
                Response.Redirect("error.aspx?ex=0", false); ////////①
            }
            else
            {
                txtUserName.Text = string.Empty;
                txtPassword.Text = string.Empty;
            }
        }
        catch (Exception ex)
        {            Response.Redirect("error.aspx?ex=" + ex.Message, false);
        }
        finally
        {
            if (sqlconn != null)
            {
                sqlconn.Close();
            }
            //sqlcmd.Dispose();
        }
    }
问题是,当走了db查询后,跳转都是正常的。如果输入框都为空。①的语句走了,但不会跳转。求大神指教。

解决方案 »

  1.   

    Response.Redirect("error.aspx?ex=" + ex.Message, true); 或者
    Response.Redirect("error.aspx?ex=" + ex.Message); 
    return;
      

  2.   

    Response.Redirect("error.aspx?ex=0", false);不加TYR,CATCH没有关系
    加了TRY,CATCH 
    要不Response.Redirect("error.aspx?ex=0");
    要不Response.Redirect("error.aspx?ex=0", true);
      

  3.   


    要不Response.Redirect("error.aspx?ex=0");
    再加个: return;