This is a migrated thread and some comments may be shown as answers.

Rad captcha validating By code.

2 Answers 141 Views
Captcha
This is a migrated thread and some comments may be shown as answers.
Deepak
Top achievements
Rank 2
Deepak asked on 07 Jan 2011, 05:57 AM
Hi guys,
I am using rad captcha in my site and want to prevent the user if
user type the wrong captcha test . So for this i am validate the captcha by coding.
But i am facing the problem that captcha always give Return false in if(radcaptcha1.isvalid) and print error.
Here my code of Default.aspx
<asp:Label ID="lblCaptcha" runat="server" ForeColor="Red"></asp:Label>
                           <telerik:RadCaptcha ID="RadCaptcha1" runat="server" validationgroup="Submit">
                        </telerik:RadCaptcha>
 <asp:UpdatePanel runat="server" ID="UPbtnUpload" >
                        <ContentTemplate>
                             <asp:ImageButton runat="server" ID="btnUpload" CssClass="btnAdd" ImageUrl="~/Images/btnUpload.jpg"
                                OnClick="btnUpload_OnClick" ValidationGroup="Submit" />
                                
                            </ContentTemplate>
                            <Triggers>
                            <asp:PostBackTrigger ControlID="btnUpload" />
                            </Triggers>
                        </asp:UpdatePanel>
And the code of default.aspx.cs is
protected void btnUpload_OnClick(object sender, EventArgs e)
       {
           RadCaptcha1.Validate();
          Page.Validate();
 
          
           if (RadCaptcha1.IsValid)
           {
                
               testimonial.ClubName = txtClub.Text;
               testimonial.Desciption = txtDiscription.Text;
               if (imageFileUpload.UploadedFiles.Count > 0)
               {
                   Guid guid = new Guid();
 
                   testimonial.FileName = imageFileUpload.UploadedFiles[0].FileName;
                   testimonial.FilePhysicalPath = imageFileUpload.TargetFolder;
                   testimonial.FileUrl = imageFileUpload.TargetFolder + imageFileUpload.UploadedFiles[0].FileName;
               }
               bool isCreated = KiwanisDataServices.CreateTestimonial(testimonial, ddlState.SelectedValue.ToString());
               ResetForm();
           }
           else
           {
               lblCaptcha.Enabled = true;
               lblCaptcha.Text = "The code you entered is not valid";
               return;
               //RadCaptcha1.ErrorMessage = "deepak";
           }
  Plz help me out for this problem there is any general solution of this.
I am structed with this problem plz telrik help me ya give me some example by this i can  accomplish it.

2 Answers, 1 is accepted

Sort by
0
Deepak
Top achievements
Rank 2
answered on 07 Jan 2011, 06:43 AM
Hello,
i did not understand why rad captcha not validate properly always return false by 
 Page.Validate();
            RadCaptcha1.Validate();
           if (Page.IsValid && RadCaptcha1.IsValid)
{
}
Plz help me asps.
0
Pero
Telerik team
answered on 11 Jan 2011, 04:11 PM
Hi Deepak,

You should place the RadCaptcha in the UpdatePanel, as I think the problem is caused by an ajax request executed before the Captcha control is validated.
The RadCaptcha control updates its code on every trip to the server, regardless if it is a full postback or Ajax postback. In case of the Ajax postback the code will not be shown on the CaptchaImage if the control is not affected by the ajax call. So, the Captcha should be placed inside an UpdatePanel.

Regards,
Pero
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Captcha
Asked by
Deepak
Top achievements
Rank 2
Answers by
Deepak
Top achievements
Rank 2
Pero
Telerik team
Share this question
or