代码!!!!!!!!!!!!!!!!
protected void btnreg_Click(object sender, EventArgs e)
    {
        if ( txtusername.Text == "" || txtuserpwd.Text  == "" || txtuserpwdtwo.Text == "" || txtuseraddress.Text == "" || txtuserphone.Text == "" || txtuserEmail.Text == "" || txtuserprotect.Text=="")
        {
            Label2.Text = "<script>alert('请填写完整再提交')</script>";        }
        else
        {
            if (HttpContext.Current.Session["CheckCode"].ToString().Equals(this.txtusercode.Text.ToString().Trim()))
            {
                SqlConnection con = new SqlConnection(connectionString);                string insertorder = "insert into users(username,userpwd,usercid,userEmail,useraddress,userphone) values('" + txtusername.Text + "','" + txtuserpwdtwo.Text + "','" + txtuserprotect.Text + "','" + txtuserEmail.Text + "','" + txtuseraddress.Text + "','" + txtuserphone.Text + "')";                SqlCommand cmd = new SqlCommand(insertorder, con);                try
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    Response.AddHeader("refresh", "0");
                      }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    Response.End();
                }
                finally
                {
                    con.Close();
                }
            }
            else
            {
                Label2.Text = "<script>alert('验证码输入不正确')</script>";
            }
        }
    }

解决方案 »

  1.   

    使用Session对象保存用户登录名的代码如下:     Session.Remove("UserName"); 
          Session["UserName"] = txtName.Text; 
           Response.Redirect("NavigatePage.aspx"); 在NavigatePage.aspx页面中,将Session对象的值显示在界面上,其代码如下:
       if (Session["UserName"] == null) 
         { 
           Response.Redirect("Default.aspx"); 
         } 
           else 
         { 
           Label1.Text =Session["UserName"].ToString(); 
         }