自动判断记录是否存在

html页面

function ValidationFunctionName1(source, arguments)

        {

            var vNumber=document.getElementById("<%=txtNumber.ClientID %>");

            var oBao=false;

            if(window.ActiveXObject)

            {

                oBao = new ActiveXObject("Microsoft.XMLHTTP");

            }

            else

            {

                oBao=new XMLHttpRequest();

            }

            //alert(userName.value);

            //alert(userpwd.value);

            oBao.open("Get","Chk.aspx?number="+ vNumber.value,false);

            oBao.send();

            var strResult = oBao.responseText;

 

            //如果返回 1 就代表可以使用,否则不能通过验证

            //alert(strResult);

            if (Number(strResult) == 1)

                arguments.IsValid = true;    

            else

                arguments.IsValid = false;

        }

 

 

<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><asp:RequiredFieldValidator

                                ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtNumber" Display="Dynamic"></asp:RequiredFieldValidator>

                            <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="重复" 

                                ControlToValidate="txtNumber" 

                                ClientValidationFunction="ValidationFunctionName1"></asp:CustomValidator>

 

chk.aspx页面

 

protected void Page_Load(object sender, EventArgs e)

        {

            Response.Clear();

            if (isNoTitle(Request.QueryString["title"].ToString()))

            {

                Response.Write("1");

            }

            else

            {

                Response.Write("0");

            }

 

            Response.End();

        }

        /// <summary>

        /// 用来判断用户在修改密码的时候原始密码是否正确

        /// </summary>

        /// <param name="admin_name">用户的昵称</param>

        /// <param name="admin_pwd">用户的原始密码</param>

        /// <returns></returns>

        public bool isNoTitle(string title)

        {

            bool sve = false;

            int i = 0;

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()))

            {

                conn.Open();

                using (SqlCommand cmd = new SqlCommand("select count(classID) from info_class where className='" + title + "'", conn))

                {

                    i = Convert.ToInt32(cmd.ExecuteScalar());

                }

            }

            if(i>0)

            {

                sve = false;

            }

            else

            {

                sve = true;

            }

 

            return sve;

        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值