验证组与recaptcha asp.net

时间:2013-02-19 15:32:51

标签: asp.net validation recaptcha

我的联系页面上有一个验证组,包含recaptcha。 我知道这是一个众所周知的问题,我按照说明操作,但每当我把验证组提交按钮RecaptchaControl_ServerValidate永远不会触发

     <asp:CustomValidator ID="RecaptchaValidator" runat="server" 
                OnServerValidate="RecaptchaValidator_ServerValidate" 
                ErrorMessage="Recaptcha input invalid." ValidationGroup="Uyelik" 
                EnableClientScript="False" />

      <recaptcha:Recaptchacontrol ID="RecaptchaControl" theme="custom" runat="server" publickey="6Lfr........."
                customthemewidget="recaptcha_widget" privatekey="6Lfr.........." />

      <asp:Button ID="btnSubmit" runat="server" Text="JOIN GOBLEN SANAT" 
        OnClick="btnSubmit_Click" ValidationGroup="Uyelik"/>

背后的代码

protected void RecaptchaValidator_ServerValidate(object source, ServerValidateEventArgs e)
    {
      this.RecaptchaControl.Validate();
      e.IsValid = this.RecaptchaControl.IsValid;
    }

 protected void btnSubmit_Click(object sender, EventArgs e)
    {

      if (Page.IsValid && RecaptchaControl.IsValid)
      {
        // do something
      }
      }
      else
      {

        lblResult.Visible = true;
        lblResult.Text = "Incorrect";

      }
    }

注意:经过15个小时的尝试,我设法让它有效,

键是CustomValidator,RequiredFieldValidator,CompareValidator和validationSummary将所有验证器的EnableClientScript变为False然后它可以工作。

1 个答案:

答案 0 :(得分:1)

试试这个:

<recaptcha:RecaptchaControl ID="RecaptchaControl" runat="server" />

<asp:CustomValidator ID="RecaptchaValidator" runat="server" OnServerValidate="RecaptchaValidator_ServerValidate" ErrorMessage="Recaptcha input invalid." ValidationGroup="SomeValidationGroup" />

代码隐藏:

protected void RecaptchaValidator_ServerValidate(object sender, ServerValidateEventArgs e)
{
    this.RecaptchaControl.Validate();
    e.IsValid = this.RecaptchaControl.IsValid;
}