register.aspx.cs

来自「visual studio 2005开发环境下采用C#语言开发的简单留言本源码」· CS 代码 · 共 76 行

CS
76
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("index.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string struserName = UserName.Text.Trim();
        string strUserPwd = PassWord.Text.Trim();
        string strrePwd = TextBox1.Text.Trim();
        string stremail = TextBox2.Text.Trim();

        if (struserName == "")
        {
            Label1.Text = "用户名不能为空!";
            UserName.Focus();
            return;
        }
        if (strUserPwd == "")
        {
            Label1.Text = "密码不能为空!";
            PassWord.Focus();
            return;
        }
        if (strrePwd == "")
        {
            Label1.Text = "确认密码不能为空!";
            TextBox1.Focus();
            return;
        }
        if (strUserPwd != strrePwd)
        {
            Label1.Text = "密码与确认密码不一致!";
            PassWord.Focus();
            return;
        }
        if (stremail == "")
        {
            Label1.Text = "邮箱不能为空不能为空!";
            TextBox2.Focus();
            return;
        }
        if ((SqlDB.getdataset("select * from UserInfo where UserName ='" + struserName + "'")).Tables[0].Rows.Count > 0)
        {
            Label1.Text = "该用户名已经存在,请换一个用户名!";
            UserName.Focus();
            return;
        }
        if (SqlDB.runsql("insert into UserInfo(UserName,UserPwd,email) values('" + struserName + "','" + strUserPwd + "','" + stremail + "')") > 0)
        {
            HttpCookie cookie = new HttpCookie("user");
            cookie["name"] = struserName;
            cookie["isAdmin"] = "0";
            cookie.Expires = DateTime.Now.AddHours(3);
            Response.Cookies.Add(cookie);
            Response.Write("<script>alert(\"恭喜您,注册成功!\");location.href=\"index.aspx\";</script>");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?