日期:2014-05-17  浏览次数:20336 次

登录控件需点击2次才能登录,如何解决?
asp.net中将登录控件放进母版页,可是在test页面中登录要点击两次登录才能够起到登录功能,请问该怎么修改??
登录控件代码如下:
  protected void Page_Load(object sender, EventArgs e)
  {
  if (Session["user"] != null)
  {
  TB_BBSUSERS user = (TB_BBSUSERS)Session["user"];
  Label1.Text = "欢迎 " + Session["username"] + " 进入!";
  MultiView1.ActiveViewIndex = 1;//用MultiView控件,里面放置2个View
  }
  else
  {
  MultiView1.ActiveViewIndex = 0;
  }
  }
  protected void LinkButton2_Click(object sender, EventArgs e)
  {
  string strCheck = TextBox1.Text.ToString();
  if (Regex.IsMatch(strCheck, "^[0-9]+$") == true)//判断账号是否为数字账号,必须的!
  {
  string id = TextBox1.Text;
  string pwd = TextBox2.Text;
  TB_BBSUSERS user = new TB_BBSUSERS();//三层结构代码
  BBSUSERSDAL bbsdal = new BBSUSERSDAL();//三层结构代码
  DataTable dt = new DataTable();
  dt=bbsdal.FindTeDingUsers(id);//三层结构代码
  if (dt.Rows.Count != 0)
  {
  user.u_userPsw = dt.Rows[0]["u_userPsw"].ToString();
  user.u_userName = dt.Rows[0]["u_userName"].ToString();
  user.u_roleId = Convert.ToInt32(dt.Rows[0]["u_roleId"]);
  Session["roleid"] = user.u_roleId;//将用户资料放入Session中以便判断
  if (user.u_userPsw==pwd)
  {
  Session["user"] = user;
  Session["username"] = user.u_userName;
  }
  else
  {
  this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('账号或者密码错误!请重新登录!');", true);
  }
  }
  else
  {
  this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('账号或者密码错误!请重新登录!');", true);
  }
  }
  else
  {
  this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('必须输入数字账号!请重新登录!');", true);
  }
  }
  protected void LinkButton1_Click(object sender, EventArgs e)
  {
  Session.Abandon();
  this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('注销成功!即将返回主页面!');", true);
  //Response.Redirect("~/Default.aspx");//注销链接到首页
  }
  protected void LinkButton3_Click(object sender, EventArgs e)
  {
  Response.Redirect("~/Perpon.aspx?id={0}");//链接到个人中心
  }

------解决方案--------------------
设置断点,单步跟踪
是否页面初始多次