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

Captcha is not validating properly when post back

3 Answers 476 Views
Captcha
This is a migrated thread and some comments may be shown as answers.
Sumanth
Top achievements
Rank 1
Sumanth asked on 14 Feb 2011, 10:21 AM
Hi,

  Below in my code in aspx and .cs files

<asp:ScriptManager ID="sm" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="upTest" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:UpdatePanel ID="upPostBack" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Button ID="btnPostBack" runat="server" Text="Post Back" OnClick="btnPostBack_Click" />
                    <asp:Label ID="lblPostBack" runat="server"></asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdatePanel ID="upc" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <telerik:RadCaptcha CssClass="rcPanel" runat="server" IgnoreCase="true" CaptchaImage-UseRandomFont="false"
                        CaptchaImage-TextChars="LettersAndNumbers" CaptchaImage-RenderImageOnly="true"
                        ID="capSignup" ValidationGroup="valSignup" ValidatedTextBoxID="txtCaptcha" ErrorMessage="error"
                        IsValid="true">
                    </telerik:RadCaptcha>
                    <asp:TextBox runat="server" ID="txtCaptcha" validateexp="required,errMsg:Enter the above code"
                        ValidationGroup="valSignup"></asp:TextBox>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:Button ID="btn" runat="server" OnClick="btn_Click" Text="Submit" ValidationGroup="valSignup" />
            <asp:Label ID="lbl" runat="server"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>

protected void btn_Click(object sender, EventArgs e)
   {
       capSignup.Validate();
       Page.Validate();
       if (capSignup.IsValid)
           lbl.Text="Valid";
       else
           lbl.Text = "In Valid";
   }
 
   protected void btnPostBack_Click(object sender, EventArgs e)
   {
       lblPostBack.Text = DateTime.Now.ToShortTimeString();
   }

Captcha is working fine when i click on "Submit" button with out clicking "Post Back" button.
If i click on "Post Back" then "Submit", IsValid property returns false.

Could any one please help me.

Thanks,
Sumanth

3 Answers, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 15 Feb 2011, 01:44 PM
Hello Sumanth,

The RadCaptcha always returns false, because after clicking the "Post Back" button, a new Captcha code is generated, but not shown on the image. RadCaptcha is designed to refresh its image on every postback and ajax request, no matter if the ajax request affects the image itself.
To resolve the issue, please set UpdateMode="Always" to the UpdatePanel containing the RadCaptcha control.

All the best,
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.
0
Mouse
Top achievements
Rank 1
answered on 14 Jul 2011, 11:29 AM
This is awful. So basically the image will keep refreshing.

In my example, I have a timer ticking and it refreshes everytime the timer ticks. My timer is there to look for an Async process to be completed and when it is then things change on the page.

Can you not configure this so that i can turn off the refresh?

In my scenario the situation may occur where the user is typing into the box and the image changes so they will be required to retype the image text.

Some advice on this matter would be helpful.

Thanks
Phil
0
Slav
Telerik team
answered on 19 Jul 2011, 12:49 PM
Hi Phillip,

A possible option in this case is to use Client Callback. When Callback occurs, the page doesn't go through full life-cycle and the code of the RadCaptcha isn't regenerated. You can implement this approach via our RadXmlHttpPanel, which loads data through Client Callbacks.

In the online demos there is section with examples that demonstrate how RadXmlHttpPanel can be used. You can also check and utilize my attached project as a basis for your further development.

I hope the provided information meets your requirements.

Regards,
Slav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Captcha
Asked by
Sumanth
Top achievements
Rank 1
Answers by
Pero
Telerik team
Mouse
Top achievements
Rank 1
Slav
Telerik team
Share this question
or