Matt
Matt

Reputation: 26971

Running Javascript after a ASP.NET postback from a client script block injected from a master page

I cannot get Javascript to run after a ASP.NET postback from a client script block injected from a master page

Below is my master page logic, and it gets hit on a postback, I have confirmed with a breakpoint.

namespace MyAwesomeProjectThatWillTakeOverTheWorldIfNotForThisIssue
{
    public partial class CommonContent : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), 
            "script", 
            "alert('Success!');", 
            true);
        }
    }
}

The problem is the alert popup only appears on the first load but not on postback.

What am I not doing right?

Upvotes: 4

Views: 2922

Answers (2)

kbrimington
kbrimington

Reputation: 25642

If you are using ASP.NET AJAX, and have a script manager on the page, consider using ScriptManager.RegisterStartupScript().

Upvotes: 3

Achilles
Achilles

Reputation: 11299

If this is an ajax triggered postback you need to use Scriptmanager.registerstartupscript

Upvotes: 1

Related Questions