引言:

   先提起初做项目时遇到的一个问题,即通过基本登陆页面(如下图示),点击登陆按钮,验证用户名、密码正确后,跳转至该用户的Main页面:

Asp.Net 页面生命周期浅析 

     登陆页面的后台代码如下:

//抱歉,注释并不是很充分
    public partial class Login : System.Web.UI.Page
    {
        
protected void Page_Load(object sender, EventArgs e)
        {
            
//为了获得在每次登录时都可以以HF开头
            txt_UserID.Text = "HF";
            txt_UserID.Focus();
        }

        
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            
string userID = txt_UserID.Text.ToString().Trim();
            UserBll userBll = new UserBll();

            List<UserInfo> userList=userBll.GetUserByID_LoginToMain(userID);
            
            
string userName = userList[0].UserName;
            
string userPsw = userList[0].UserPsw;
            
string styleID = userList[0].StyleID.ToString().Trim();
            
string departID = userList[0].DepartID.ToString().Trim();
            
string email = userList[0].Email.ToString().Trim();
            
//判断工号以及密码输入
            if (txt_UserID.Text == "" || txt_UserPsw.Text == "")
            {
                Response.Write("<script language=javascript>alert('Please input more...')</script>");
            }
            
else if (txt_UserPsw.Text == userPsw)
            {
                UserInfo user = new UserInfo();
                user.UserID = userID;
                user.UserName = userName;
                user.UserPsw = userPsw;
                user.StyleID = int.Parse(styleID);
                user.DepartID =int.Parse(departID);
                user.Email = email;

                Session["UserInfo"= user;
                Response.Redirect("main.aspx");
                
//Response.Redirect("main.aspx?>        }

相关文章:

  • 2021-07-25
  • 2022-02-15
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2022-02-03
  • 2021-07-04
  • 2022-03-09
相关资源
相似解决方案