<asp:TextBox ID="txtNum" runat="server" Width="400px" ></asp:TextBox>
<asp:CustomValidator ID="cvNum" runat="server" ErrorMessage="此登记证号已存在!请勿重复添加!" onservervalidate="cvNum_ServerValidate" ControlToValidate="txtNum" SetFocusOnError="True" Display="Dynamic"></asp:CustomValidator>
protected void cvNum_ServerValidate(object source, ServerValidateEventArgs args)
{
DataTable dt = DB.GetDataTable("i_id", "tab_dengji", "dengjihao='" + txtNum.Text.Trim() + "'", "");
args.IsValid = false;
if (Request.QueryString["id"] != null)
args.IsValid = true;
else
{
if (dt != null && dt.Rows.Count > 0)
args.IsValid = false;
else
args.IsValid = true;
}
}