protected void txt_IDCode_TextChanged(object sender, EventArgs e) { DateTime BirthDay; int Sex; TextBox txt_birthday = UC_DetailView1.FindControl("PM_Promotor_Birthday") != null ? (TextBox)UC_DetailView1.FindControl("PM_Promotor_Birthday") : null; DropDownList ddl_sex = UC_DetailView1.FindControl("PM_Promotor_Sex") != null ? (DropDownList)UC_DetailView1.FindControl("PM_Promotor_Sex") : null; if (Tools.DoVerifyIDCode(((TextBox)sender).Text, out BirthDay, out Sex) && ((TextBox)sender).Text.Trim().Length == 18) { if (txt_birthday != null) { txt_birthday.Text = BirthDay.ToString("yyyy-MM-dd"); } if (ddl_sex != null) { ddl_sex.SelectedValue = Sex.ToString(); } if (DateTime.Now < BirthDay.AddYears(16) || DateTime.Now > BirthDay.AddYears(50)) { int year = DateTime.Now.Year - BirthDay.Year; if (BirthDay.AddYears(year) > DateTime.Now) { year++; } MessageBox.Show(this, "对不起,该导购年龄不符合规则(16~49岁),该人员年龄:" + year); return; } } else { MessageBox.Show(this, "身份证号码错误!"); ((TextBox)sender).Text = ""; if (txt_birthday != null) { txt_birthday.Text = ""; } if (ddl_sex != null) { ddl_sex.SelectedValue = "0"; } return; } }