Call javascript function after validation

2 posts, 0 answers
  1. Anders
    Anders avatar
    1 posts
    Member since:
    Mar 2008

    Posted 05 Mar 2010 Link to this post

    Hi, is there a good way to call a javascript method after the Captcha check is validated?

    Im trying to add the captcha to a blog comment module. The module uses jquery to post the comment.

  2. Pero
    Pero avatar
    1156 posts

    Posted 09 Mar 2010 Link to this post

    Hello Anders,

    The easiest way to call a JavaScript function after the Captcha has been validated correctly is to register a script from the server. The source code pasted below renders a script from the server, that attaches an event handler to the "load" (MS AJAX Framework) specific event.

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head id="Head1" runat="server">
        <script type="text/javascript">
            function TestMethod()
                alert("Captcha Valid!");
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Wrong Input" Width="386px">
            <asp:Button ID="Button1" runat="server" Text="Validate Input" CausesValidation="true"
                OnClick="Button1_Click" />

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public partial class Captcha_CallJS_afterPostback : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        protected void Button1_Click(object sender, EventArgs e)
            if (Page.IsValid)
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Validate", "Sys.Application.add_load(TestMethod);", true);

    Kind regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top