1

我在我的联系页面上有一个验证组,带有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 即可。

4

1 回答 1

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;
}
于 2013-02-19T15:44:21.403 回答