Hi,
I am doing booking form page for the members with Radcaptch validation.
<telerik:RadCaptcha ID="RadCaptcha1" runat="server" ValidationGroup="SubmitInfo"
ErrorMessage="The code you entered is not valid." Display="Dynamic">
</telerik:RadCaptcha>
I given the ValidationGroup Property to textbox requiredfield validation and submit button also.
RequiredFieldValidator is validating for textbox but radcaptch is not validating
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="SubmitInfo"
runat="server" ControlToValidate="txtemail" ErrorMessage="Enter Email"></asp:RequiredFieldValidator>
<asp:Button ID="btnbooking" runat="server" ValidationGroup="SubmitInfo" Text="Submit"
OnClick="btnbooking_Click" />
Please help in the issue which i stucked for 3 days.
Urgent reply highly appreciable
Regards,
Prathap Narravula
7 Answers, 1 is accepted
Could you please explain in more detail what do you mean by "RadCaptcha is not validating"?
Please note that the RadCaptcha control does not support client-side validation. A post back to the server is needed in order for the Captcha to perform validation. So if at first sight it seems that the Captcha does not validate, but the other validators do, it is because the they also support client-side validation and prevent the WebForm from submitting if the page is not valid.
In case you check for the IsValid property on the server, in the button's click event handler, then you should call RadCaptcha's Validate and Page's Validate(ValidationGroup), to be sure that validation has occurred, before checking the IsValid flag.
Note that if you dynamically create the Captcha control, you must add it to the page on every postback, and before the ViewState is loaded. That is if you add the control in the Page.Load, it is too late, because the ViewState has been loaded, and the Captcha will always invalidate the code. Our suggestion is to use the Page.Init method instead.
All the best,
Pero
the Telerik team
You must:
- Enter value for ErrorMessage property
- ValidationGroup must match the ValidationGroup name on the ValidationSummary and the button that causes the PostBack.
- The button causing the PostBack must have CausesValidation set to true.
Remember that the
RadCaptcha does NOT have client-side validation like many of the other controls
on your page. You will not see
RadCaptcha validation until the page is posted back to the server. Other controls that have client-side
validation will warn user of errors without posting the page back to the server
which means your RadCaptcha wont validate at that point. This may give the appearance that your RadCaptcha validation is not working.
www.BlueCanyonSoftware.com
You can validate the RadCaptcha via a custom RadTextBox and give an ASP RequiredFieldValidator to the particular RadTextBox to prevent the postback if it is empty. The custom RadTextBox for RadCaptcha can be given by
1. Setting the propery CaptchaImage.RenderImageOnly to true to render only the captcha image without the TextBox and Label of the control.
2. Setting the property ValidatedTextBoxID to the ID of the RadTextBox which you want to use
for entering the RadCaptcha code.
Please have a look at the following code I tried which works fine at my end.
ASPX:
<
telerik:RadCaptcha
ID
=
"RadCaptcha1"
runat
=
"server"
ErrorMessage
=
"Invalid Captcha"
IgnoreCase
=
"true"
CaptchaImage-RenderImageOnly
=
"true"
ValidatedTextBoxID
=
"RadTextBox1"
>
</
telerik:RadCaptcha
>
<
br
/>
<
telerik:RadTextBox
ID
=
"RadTextBox1"
runat
=
"server"
>
</
telerik:RadTextBox
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator1"
runat
=
"server"
ErrorMessage
=
"*"
ForeColor
=
"Red"
ControlToValidate
=
"RadTextBox1"
></
asp:RequiredFieldValidator
>
<
br
/>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
Text
=
"Submit"
CausesValidation
=
"true"
OnClick
=
"RadButton1_Click"
>
</
telerik:RadButton
>
Thanks,
Shinu.
Usually the validated textbox gets cleared after the postback, so it is strange that this happens even before the RequiredFieldValidator validates the input. I would suggest checking if there is a custom client-side script that clears the textbox before validation. Also, you can send a fully runnable sample that isolates your scenario and I will do my best to locate the cause of the issue.
Regards,
Slav
Telerik
please try the following coding on client button clicking event.
Declare a label - lblCaptchaErr to display the error msg
Assume your Captcha named as RadCaptcha1
On button clicking event
if (document.getElementById('RadCaptcha1_CaptchaTextBox').value == "") {
document.getElementById('<%= lblCaptchaErr.ClientID %>').innerHTML = "Please enter the Captcha Code";
args.set_cancel(true);
}
Thanks