how to load new captcha image from javascripts

2 posts, 0 answers
  1. sai nsrs
    sai nsrs avatar
    4 posts
    Member since:
    Apr 2010

    Posted 06 Sep 2011 Link to this post

    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.
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 08 Sep 2011 Link to this post

    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 >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top