Invalid code on page with RadAjaxManager

2 posts, 1 answers
  1. tomekm
    tomekm avatar
    38 posts
    Member since:
    Mar 2009

    Posted 18 Dec 2009 Link to this post

    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?

  2. Answer
    Pero avatar
    1156 posts

    Posted 19 Dec 2009 Link to this post

    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:
      <form id="form1" runat="server">
          <asp:ScriptManager ID="ScriptManager1" runat="server">
          <telerik:RadAjaxManager ID="AjaxManager1" runat="server">
                  <telerik:AjaxSetting AjaxControlID="Button2" EventName="Click">
                          <telerik:AjaxUpdatedControl ControlID="Label2" />
              <asp:Label ID="Label1" runat="server" Text="" ForeColor="Red"></asp:Label>
              <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                      <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Invalid Input"
              <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>

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

    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.
Back to Top