Error registering client scrip block when using master page in an ASP.NET application
<p>I've got this code from <a href="http://madskristensen.net/post/JavaScript-AlertShow%28e2809dmessagee2809d%29-from-ASPNET-code-behind.aspx" rel="nofollow">Mads Kristensen's blog</a> to display a message box on an ASP.NET client's page using Javascript:</p>

<pre><code>public static class Alert
{
    public static void Show(string message)
    {
        // Cleans the message to allow single quotation marks 
        string cleanMessage = message.Replace("'", "\\'");
        string script = "&lt;script type=\"text/javascript\"&gt;alert('" + cleanMessage + "');&lt;/script&gt;";

        // 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 &amp;&amp; !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script, false);
        }
    }
}
</code></pre>

<p>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?</p>

<p>Thanks.</p>
