page.IsValid ALWAYS return True

1,501 views
Skip to first unread message

Shai

unread,
Jul 27, 2011, 9:13:51 AM7/27/11
to reCAPTCHA
Hi there,

I am trying to work with the reCaptcha control in my ASP.NET page.

The control is showing right on the page and seems to work, my problem
is that no matter if I type anything in the reCapcha control the test
Page.IsValid always return true.

Any Idea why ?

Shai

unread,
Jul 27, 2011, 9:22:20 AM7/27/11
to reCAPTCHA
I am using this control below a Formview control and I am testing for
Page.IsValid in the Formview_Inserting event handler and I always get
there Page.IsValid = True

Innovater

unread,
Jul 28, 2011, 3:31:13 AM7/28/11
to reCAPTCHA
Hi shai,
I am facing the same problem getting the Page.IsValid =
True after typing the first word.Anybody have any Idea.

David Broadhead

unread,
Aug 4, 2011, 6:12:00 AM8/4/11
to reCAPTCHA
I'm getting this issue to. Any got an answer yet? Page.IsValid is
always true as is the IsValid property of the reCaptcha control

Any ideas?

mike300zxt

unread,
Aug 9, 2011, 3:18:30 PM8/9/11
to reCAPTCHA
I'm having the same problem. Any solutions? Is this control broken?
Or is there something else needed that isn't documented?

Mike McGuinness

unread,
Aug 9, 2011, 3:55:27 PM8/9/11
to reCAPTCHA
If you're using the ASP.NET reCaptcha control, the documentation
(example) fails to mention that you need to manually call
recaptcha.Validate() before you check the recaptcha.IsValid or
Page.IsValid properties.

From looking at the control code and issue tracking, it seems like
this was a bug or change made in version 1.0.4.0 and 1.0.5.0. Call
recaptcha.Validate() before you check IsValid, and it seems to work.

- Mike

Adrian Godong

unread,
Aug 9, 2011, 4:15:30 PM8/9/11
to reca...@googlegroups.com
Hi,

This is *not* true. Do you have the exact revision number that we can check?

.Validate() will be automatically called by ASP.NET, unless you set
ValidationGroup (in which case, it is not supported at all).

Thanks,

> --
> You received this message because you are subscribed to the Google Groups "reCAPTCHA" group.
> To post to this group, send email to reca...@googlegroups.com.
> To unsubscribe from this group, send email to recaptcha+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/recaptcha?hl=en.
>
>

--
Adrian Godong
adrian...@gmail.com

Mike McGuinness

unread,
Aug 9, 2011, 4:46:06 PM8/9/11
to reCAPTCHA
Thanks for the clarification Adrian. When I did a google search on
this problem, I found a lot of people are having this problem, and
none of the threads had any answers. I didn't see any disclaimer
about it not working with standard ASP.NET validation mechanisms like
ValidationGroup on the sample page documentation. I'm not an expert
in using Google Labs, so maybe I missed it. But when I dug into it a
bit, I did see an issue logged about it being a bug in 1.0.4.0 and
1.0.5.0, so I assumed that was the case. I guess I miss-read the bug.

I can't show you my full source as the page contains numerous forms
and ajax controls, all loaded at runtime through a custom CMS, but
here's the jist of what I did to get it to work:

In my HTML, I added a CustomValidator control to handle error
messaging (Your example uses a label, which works too)

<asp:CustomValidator ID="recaptchaValidator" runat="server"
Display="Dynamic"

CssClass="failureNotification"
ValidationGroup="RegisterUserValidationGroup"
OnServerValidate="recaptchaValidator_ServerValidate"
ErrorMessage="Please enter
the words shown in the ReCaptcha box.">*</asp:CustomValidator>

In my code-behind, I added a ServerValidate hander for the
CustomValidator control that manually calls recaptcha.Validate(), and
updates the event's IsValid property, which bubbles up to the
Page.IsValid property. In the case of your example where a label was
used to show errors, your could call the recaptcha.Validate() before
checking the Page.IsValid property.

protected void recaptchaValidator_ServerValidate(object source,
ServerValidateEventArgs e)
{
recaptcha.Validate();
e.IsValid = recaptcha.IsValid;
}

protected void btnRegister_Click(object sender, EventArgs e)
{
// if (Page.IsValid) Save New User
// else ValidationSummary get's shown to display errors
}


Hope that clarifies things. It seems to work great, even if it is not
supported at all. It's a great control! Maybe the documentation just
needs a little clarification to help out all the people who can't get
it to work with ASP.NET forms.

- Mike

Adrian Godong

unread,
Aug 9, 2011, 5:03:27 PM8/9/11
to reca...@googlegroups.com
Regarding the ValidationGroup, while this is quite "standard" in how
.NET validators work, it seems that Microsoft overlooked the idea of
custom, non-textbox based validators. The ValidationGroup property
works only on BaseValidator implementation but reCAPTCHA does not.
There is already a long discussion about this and there is already a
workaround for it.

Regarding the issue log: I have closed that issue since I can't repro
it (nor there is any sample code that I can verify). We're not working
on reCAPTCHA libraries full time so those can get backlogged. Thanks
for reminding me.

In your case: if you need to use ValidationGroup, there is already a
lot of discussion going on:

The original issue:
http://code.google.com/p/recaptcha/issues/detail?id=93&can=1&

The original discussion:
http://groups.google.com/group/recaptcha/browse_thread/thread/f4ce9cab3ac52bf?pli=1

There is a reason why the control does not have a ValidationGroup
property, and this is why.

HTH,

Reply all
Reply to author
Forward
0 new messages