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

Invalid code on page with RadAjaxManager

1 Answer 74 Views
Captcha
This is a migrated thread and some comments may be shown as answers.
tomekm
Top achievements
Rank 1
tomekm asked on 18 Dec 2009, 03:49 PM

I have a page with Captcha and with RadAjaxManager that updates some content (comboboxes) on the page.

When I open the page, select comboboxes (that make partial postback) and then enter correct code (I'm 100% sure) then I get the wrong code message. When I reenter code, it works. 

It happens every time I open that page. Maybe when combobox get selected and ajax request is done, the captcha image is no longer up to date and that's why I got the error. Is there any solution to that?

1 Answer, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 19 Dec 2009, 04:10 PM
Hi Rychu,

This is expected behavior of the RadCaptcha control and it is so by design. When an AJAX request is fired, the server-side page goes through its full page life cycle. This means that a new RadCaptcha code will be generated, but because it's an AJAX update it would not be shown on the image (the old code is still shown because the RadCaptcha is not affected by the partial page update). So, the user sees the old code and enters it correctly but still gets an Error Message, because this old code is not valid anymore. To overcome this, our suggestion is to use the following solution:

  • Place the RadCaptcha inside an UpdatePanel (or AJAX Panel) so that the code is updated when AJAX update occurs (UpdateMode must be Always). For your convenience I have created a sample project that implements the explained functionality. Here is the full source code:
    .aspx
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <telerik:RadAjaxManager ID="AjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="Button2" EventName="Click">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Label2" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <div>
            <asp:Label ID="Label1" runat="server" Text="" ForeColor="Red"></asp:Label>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Invalid Input"
                        ValidationGroup="VG">
                    </telerik:RadCaptcha>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:Button ID="Button1" runat="server" Text="Verify Code" ValidationGroup="VG" />
            <br />
            <br />
            <br />
            <br />
            <asp:Button ID="Button2" runat="server" Text="AJAX" OnClick="Button2_Click" />
            <asp:Label ID="Label2" runat="server"></asp:Label>
        </div>
        </form>

    .cs
    protected void Button2_Click(object sender, EventArgs e)
    {
        Label2.Text = DateTime.Now.ToString();
    }


Regards,
Pero
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Captcha
Asked by
tomekm
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or