我在前台使用了ASP。NET的CompareValidator验证控件,是用来验证验证码使用的。
可是我点击提交时,直接就跳过了这步。没有进行验证,而是直接把数据发到后台去。
我要如何做。才能让CompareValidator先行验证?

解决方案 »

  1.   

    前台 <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtVali"
                                            ControlToValidate="TextBox1" ErrorMessage="*验证码有误,请重新输入" Display="Dynamic"></asp:CompareValidator>
                                        <asp:TextBox ID="TextBox1" runat="server" Width="55" Visible="False" />后台    protected void Page_Load(object sender, EventArgs e)
        {        TextBox1.Text = Convert.ToString(Session["ValidateCode"]);
        }
        protected void Submits(object sender, EventArgs e) 
        {
            
            JobManager jobManager = new JobManager();
            Job job = new Job();        job.UserName = txtUserName.Text.Trim();
            job.Jobquestion = txtQuestion.Text.Trim();
            job.JobAnsewer = txtAnswer.Text.Trim();        if (jobManager.JobFinkKey(job) != null)
            {
                Response.Redirect("ChangePwd.aspx");
            }
            else 
            {
                Response.Write("<script type='text/javascript'>alert('您所提供的资料有误,请认真填写!');location.href='ForgetKey.aspx'</script>");
            }
            
        
        }
      

  2.   

    LZ加上这段代码:
    protected void Submits(object sender, EventArgs e) 
        {         if (Page.isValid) {        JobManager jobManager = new JobManager(); 
            Job job = new Job();         job.UserName = txtUserName.Text.Trim(); 
            job.Jobquestion = txtQuestion.Text.Trim(); 
            job.JobAnsewer = txtAnswer.Text.Trim();         if (jobManager.JobFinkKey(job) != null) 
            { 
                Response.Redirect("ChangePwd.aspx"); 
            } 
            else 
            { 
                Response.Write(" <script type='text/javascript'>alert('您所提供的资料有误,请认真填写!');location.href='ForgetKey.aspx' </script>"); 
            } 
            
           }
        }
      

  3.   

    你在前台是不是有几个验证控件啊?
    你在CompareValidator 控件,和按钮的validGroup都设置为同一个值.再试试..
      

  4.   

    if (Page.isValid)解决了。谢谢
      

  5.   

    使用了验证控件后,要
    if (Page.isValid)
    {
      //your code
    }