Running Javascript after ASP.NET postback from the client script block entered from the main page

I cannot get Javascript to run after ASP.NET postback from the client script block entered from the main page

Below is my main page logic, and it gets into postback, I 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 that the popup only appears on first boot, but not on postback.

What am I not doing right?

+4
source share
2 answers

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

+3
source

If it's an ajax callback, you need to use Scriptmanager.registerstartupscript

+1
source

All Articles