简体   繁体   中英

How to call javascript function from code-behind after ajax postback

I'm using Telerik controls in my project and I am using RadTabStrip for my purposes

<telerik:RadTabStrip ID="tsRequisitions" Skin="" MultiPageID="mpRequisitions" runat="server" Width="980"  ScrollButtonsPosition="Right" ScrollChildren="True" OnTabCreated="tabCreated">

As you can see in this template I call tabCreated method every time when new tab has created. Now I want to call some javascript function from server-side(all mentioned is in RadAjaxPanel).

I've tried to use RegisterClientScriptBlock , but it didn't help me to fire my javascript function.

if (!ClientScript.IsClientScriptBlockRegistered("tabSelected"))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(),
                    "tabSelected", "TabSelected();", true);
            }

And I have this in my .aspx file

<script type="text/javascript">
    function TabSelected() {
       console.log("dfgdfgfdg");
    }          
</script>

How can I call my function from code-behind after AJAX postback?

The following code snippet do the trick

RadScriptManager.RegisterStartupScript(this,this.GetType(), "tabSelectedScript", "TabSelected();", true);

RegisterStartupScript is static method of RadScriptManager class (I'm using Telerik controls here again, but maybe it will work with asp.net standart ScriptManager too).

你尝试过这个吗?

    Page.RegisterStartupScript("OnLoad", "<script>TabSelected();</script>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM