日期:2014-05-16 浏览次数:20541 次
<asp:CustomValidator ID="cvIdentity" runat="server" ControlToValidate="txtIdentity" ErrorMessage="身份证号错误" SetFocusOnError="True"
OnServerValidate="cvIdentity_ServerValidate" ClientValidationFunction="Identity_ClientValidate"></asp:CustomValidator>
function Identity_ClientValidate(source, args)
{
var str = args.Value;
if(str.length < 3)
{
if (str.length != 0)
{
args.IsValid = false;
}
return;
}
var xmlHttp = new XMLHttpRequest();
var url = "CheckProCode.aspx" + "?ID=" + str;
xmlHttp.onreadystatechange = function ()
{
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
if (xmlHttp.responseText == "身份证号错误")
{
args.IsValid = false;
}
}
}
xmlHttp.open("GET", url, true);
xmlHttp.timeout = 10000;
xmlHttp.send(null);
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string ConStr = WebConfigurationManager.ConnectionStrings["SqlConString"].ToString();
string code = Request.QueryString["ID"].Substring(0, 3);
SqlConnection Con = new SqlConnection(ConStr);
Con.Open();
SqlCommand Cmd = new SqlCommand("SELECT * FROM PROVINCE WHERE DigitalCode =" + code, Con);
SqlDataReader dtrSql = Cmd.ExecuteReader();