I've got this code from Mads Kristensen's blog to display a message box on an ASP.NET client's page using Javascript:
public static class Alert
{
public static void Show(string message)
{
// Cleans the message to allow single quotation marks
string cleanMessage = message.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
// Gets the executing web page
Page page = (Page)HttpContext.Current.CurrentHandler;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script, false);
}
}
}
And it works fine when there is no master page involved. However, when I call it (on the server side) from a master page derived page it doesn't work. I'm guessing it is something related to the RegisterClientScriptBlock() method, but I don't know what. Can someone show me the way to solve this?