4

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

@Achilles, honestly, I'd be dead in the water without Intellisense, what with the subtle differences between method names and scope (static vs. instance) between ScriptManager and Page.ClientScript.
1

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

1 Comment

Try referencing the current child page and pass that into the scriptmanager.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.