using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class zhuce : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)//判断是否为响应回发 { Insert("0001"); } } //联动 protected void DropDownListSheng_SelectedIndexChanged(object sender, EventArgs e) { string Code = DropDownListSheng.SelectedItem.Value; List<ChinaStates> listShi = new ChinaStatesDA().SelectByParentAreaCode(Code); DropDownListShi.DataSource = listShi; DropDownListShi.DataTextField = "AreaName"; DropDownListShi.DataValueField = "AreaCode"; DropDownListShi.DataBind(); UpdatePanel1.Update(); } //初始加载页面的地区显示 public void Insert(string parentCode) { List<ChinaStates> listSheng = new ChinaStatesDA().SelectByParentAreaCode(parentCode); DropDownListSheng.DataSource = listSheng; DropDownListSheng.DataTextField = "AreaName"; DropDownListSheng.DataValueField = "AreaCode"; DropDownListSheng.DataBind(); List<ChinaStates> listShi = new ChinaStatesDA().SelectByParentAreaCode("11"); DropDownListShi.DataSource = listShi; DropDownListShi.DataTextField = "AreaName"; DropDownListShi.DataValueField = "AreaCode"; DropDownListShi.DataBind(); List<ChinaStates> listDiqu = new ChinaStatesDA().SelectByParentAreaCode("1101"); DropDownListDdiqu.DataSource = listDiqu; DropDownListDdiqu.DataTextField = "AreaName"; DropDownListDdiqu.DataValueField = "AreaCode"; DropDownListDdiqu.DataBind(); } //地区联动 protected void DropDownListShi_SelectedIndexChanged(object sender, EventArgs e) { string Code = DropDownListShi.SelectedItem.Value; List<ChinaStates> listDiqu = new ChinaStatesDA().SelectByParentAreaCode(Code); DropDownListDdiqu.DataSource = listDiqu; DropDownListDdiqu.DataTextField = "AreaName"; DropDownListDdiqu.DataValueField = "AreaCode"; DropDownListDdiqu.DataBind(); UpdatePanel1.Update(); } //用户名文本改变时触发 protected void txtuser_TextChanged(object sender, EventArgs e) { if (txtuser.Text.Length<4) { LabelUser.Text = "用户名长度不能小于4"; } else { bool isok = new UsersDA().CheckUsersName(txtuser.Text); if (isok) { LabelUser.Text = "√"; } else { LabelUser.Text = "X"; } } } //姓名文本改变时触发 protected void txtname_TextChanged(object sender, EventArgs e) { if (txtname.Text.Length<4) { LabelName.Text = "用户名长度不能小于4"; } else { LabelName.Text = "√"; } } //密码文本改变时触发 protected void txtpwd_TextChanged(object sender, EventArgs e) { if (txtpwd.Text.Length<6) { LabelPwd.Text = "密码长度不能小于6位"; } else { LabelPwd.Text = "√"; } } //判断密码是否一致 protected void txtpwd2_TextChanged(object sender, EventArgs e) { if (txtpwd2.Text==txtpwd.Text) { LabelPwd2.Text = "√"; } else { LabelPwd2.Text = "两次密码不一致"; } } //注册按钮 protected void Button1_Click(object sender, EventArgs e) { try { Users p = new Users(); p.UsersName = txtuser.Text; p.Name = txtname.Text; p.Pwd = txtpwd.Text; p.Account = txtpwd2.Text; p.Sex = RadioButton1.Checked == true ? "男" : "女"; p.Home = DropDownListSheng.SelectedItem.Text + DropDownListShi.SelectedItem.Text + DropDownListDdiqu.SelectedItem.Text; p.Brithday = DateTime.Parse(txtbir.Text); p.Tel = txttel.Text; p.QQ = txtqq.Text; p.Email = txtemail.Text; new UsersDA().Insert(p); var re = base.Response; re.Redirect("LogInss.aspx"); } catch (Exception) { Response.Write("<script>alert('填写信息有误')</script>"); } finally { var re = base.Response; re.Redirect("zhuce.aspx"); } } //判断邮箱输入格式 protected void txtemail_TextChanged(object sender, EventArgs e) { MatchCollection mc = Regex.Matches(txtemail.Text.ToString().Trim(), @"[a-zA-Z0-9_-.]+@w+(.w+)+"); if (mc!=null) { } else { Labelemail.Text = "邮箱格式不正确"; } } }