Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Captcha > how to load new captcha image from javascripts

Not answered how to load new captcha image from javascripts

Feed from this thread
  • sai nsrs avatar

    Posted on Sep 6, 2011 (permalink)

    HI, Can you please tell me , how to reload new captcha image from javascript when ever client side validation of other controls fails in the same page.

    Reply

  • Pero Pero admin's avatar

    Posted on Sep 8, 2011 (permalink)

    Hi Sai,

    This can be easily achieved with a bit of JS code. Note that you must enable the refresh image functionality.
    Here is a sample code that refreshes the image on a button click:
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <script type="text/javascript">
            function RefreshImage()
            {
                var captcha = $find("<%=RadCaptcha1.ClientID %>");
                document.location = $get(captcha.get_id() + "_CaptchaLinkButton").href;
            }
        </script>
        <div>
            <input type="button" onclick="RefreshImage(); return false;" value="RefreshImage" />
            <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Invalid Code" ValidationGroup="Group"
                EnableRefreshImage="true" Width="400px" ForeColor="Red">
            </telerik:RadCaptcha>
            <asp:Button ID="Button1" runat="server" Text="Validate Code" ValidationGroup="Group" />
        </div>
        </form>
    </body>
    </html>

    Greetings,
    Pero
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Captcha > how to load new captcha image from javascripts