Firing Javascript function After Postback

7 posts, 0 answers
  1. bouchart
    bouchart avatar
    41 posts
    Member since:
    Apr 2011

    Posted 20 Oct 2011 Link to this post


    I want to execute a javascript function, after a button click

    It's easy to execute javascript and after postback  on the same button, but not postback and after javascript !

    Please help me !

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Oct 2011 Link to this post

    Hello Levefaude,

    You can try the following approaches to execute javascript after a button click.

    1. C#:
    protected void btn_Click(object sender, EventArgs e)
      string radconfirmscript = "<script language='javascript'>function f(){test(); Sys.Application.remove_load(f) ;}; Sys.Application.add_load (f);</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "radconfirm", radconfirmscript);

    <script type="text/javascript">
    function test()

    2. C#:
    protected void Button1_Click(object sender, EventArgs e)
       Response.Write("<script language=JavaScript> alert('Hello'); </script>");

    3. C#:
    protected void Button1_Click(object sender, EventArgs e)
       string s = "<script language=JavaScript>alert('Hello');</script>";
       Page.ClientScript.RegisterStartupScript(this.GetType(), "test", s);

  3. bouchart
    bouchart avatar
    41 posts
    Member since:
    Apr 2011

    Posted 21 Oct 2011 Link to this post

    Thank you, but it does not work with an a little bit complex procedure

    I am surprised that telerik is not planned an afterpostback feature for the controls!!!!
    Anthem, free library, had planned everything!

    Thank you and have a good day

  4. Slav
    Slav avatar
    1359 posts

    Posted 25 Oct 2011 Link to this post

    Hi Levefaude,

    I would also recommend using the RegisterStartupScript method of the ScriptManager control in order to register a client script that will be executed after the postback. This method can be used as shown below:

    Page Markup:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <form id="form1" runat="server">
        <asp:ScriptManager ID="Scriptmanager1" runat="server" />
            <telerik:RadButton runat="server" ID="RadButton" Text="Click"

    protected void RadButton_Click(object sender, EventArgs e)
        string script = "alert('Hello');";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "testScript", script, true);

    The afterpostback feature that you are suggesting is indeed interesting. It will be brought to the attention of our developers and it will be considered for implementation, depending on its popularity. I have logged this request as a PITS Issue. You can check its status by following this link: Public URL.

    Feel free to contact us again if you encounter more difficulties.

    All the best,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  5. bouchart
    bouchart avatar
    41 posts
    Member since:
    Apr 2011

    Posted 27 Oct 2011 Link to this post

    Yesss ! Thank you, that works very well

    Very good day, rainy in France

  6. Jay
    Jay avatar
    59 posts
    Member since:
    Apr 2009

    Posted 24 Aug 2015 Link to this post

    I've been struggling with this for a few days now and can't seem to get it to work. I'm guessing my problem might be that I've got a more complicated situation with 2 master pages and a couple ascx pages? .ascx page #1 has a folder tree on right and loads .ascx page #2 based on what folder is clicked.

    Here's my issues:
    1. If I put the script in the .ascx page it doesn't get added to the page. I have to put it in the .aspx page that calls the 2 ascx controls.
    2. It will show up in my debugging but it never gets hit?

    Here's what I'm using code wise (
    JS call inside of a Telerik:RadCodeBlock

    function viewFolderDocuments() {
                var strUrl;
                strUrl = '<%=GetViewStateString(PDMPlanroom.QUERY_STR_VIEW_URL)%>';
      , "_blank");

    Then my codebehind button click event has this code:

    Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "viewFolderDocuments", "viewFolderDocuments();", True)

    The script NEVER gets hit?


  7. bouchart
    bouchart avatar
    41 posts
    Member since:
    Apr 2011

    Posted 25 Aug 2015 in reply to Jay Link to this post

    If it can help you

    1 / We are also working with a treeview on a main page PP

    Our page is divided into two radpane by a splitter

    Click on treeview (client side) , we modified the right radPane adress

    function onClientNodeClick(sender, args) {
    var treeNode = args.get_node();
    var ZoneDetail = $find("<%=PaneDetail.ClientID%>");

    var Categorie = treeNode._attributes.getAttribute("Categorie");
    var ID = treeNode.get_value();
    NoeudEnCours = treeNode;

    switch (Categorie) {
    ZoneDetail.set_contentUrl(repPersonnes + "Personne.aspx?Action=M&PerID=" + ID);
    FicheEnCours.Action = "M";

    ZoneDetail.set_contentUrl(repForets + "Foret.aspx?Action=M&ForID=" + ID);

    2 / To update the treeview from the detail page PD ....
    Server side
    PrivateSub MajTreeviewPrinc(CPCommune AsString)
    Dim Libelle AsString


    Fnscript = "<script>Maj('" & Libelle & "')</script>"
    ScriptManager.RegisterStartupScript(Page, Me.GetType(), "Maj", Fnscript, False)
    Catch Ex AsException



    Client Side

    function Maj(LibelleNom) {
    var tv = window.parent;

    And on PP

    Client Side

    function MajLibelle(libelle) {
    treeView = $find("<%= tvPersonnes.ClientID %>");
    var node = treeView.get_selectedNodes();

    Have a good day



Back to Top