I am using the ASP.Net plugin and control provided by reCAPTCHA. I can successfully get the control to work if the submit button on the web form is not in a validationgroup. There is no validationgroup attribute for the reCAPTCHA control.
Has anybody had any success with this or any solutions to get the reCAPTCHA control to work when there is a validationgroup on the web form?
Thought I'd just expand on the comments by a few others with some working code...
<recaptcha:RecaptchaControl ID="RecaptchaControl" runat="server" />
<asp:CustomValidator ID="RecaptchaValidator" runat="server" OnServerValidate="RecaptchaValidator_ServerValidate" ErrorMessage="Recaptcha input invalid." ValidationGroup="SomeValidationGroup" />
And code behind...
protected void RecaptchaValidator_ServerValidate(object sender, ServerValidateEventArgs e)
{
this.RecaptchaControl.Validate();
e.IsValid = this.RecaptchaControl.IsValid;
}
Can anyone think of a simpler way of doing it? Kudos to Vidalik for the thoughts about using OnServerValidate.
You can add CustomValidator, implement OnServerValidate that would validate the ReCAPTCHA data. CustomValidator can be assigned to any ValidatorGroup.
The reCAPTCHA ASP.NET plug-in is written to be backward-compatible with ASP.NET 1.1, which means the ValidationGroup
concept (which is new in ASP.NET 2.0) is not supported. But the plug-in comes with downloadable source code, so you can modify it yourself to support ValidationGroup
.
In ASP.NET 2.0, validators should inherit from BaseValidator
and implement IValidator
, which means you should change the RecaptchaControl type to inherit from BaseValidator
instead of WebControl
. You will then have to modify the code a bit to implement all methods and properties defined in BaseValidator
. Then you can use this new control on your page instead, which now supports ValidationGroup
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With