How to use ScriptManager in class file?

user240141 picture user240141 · Aug 5, 2011 · Viewed 20.1k times · Source

I Have a common method that displays alert message using page.clientScript. But later on i added update panel. Now this piece of code is not working. So I need to call there scriptmanager, but i get some error message that it is accessible there. Below is my ShowMessage method of common.cs file

 private static void ShowMessage(Page currentPage, string message)
        {
            var sb = new StringBuilder();
            sb.Append("alert('");
            sb.Append(message);
            sb.Append("');");
            currentPage.ClientScript.RegisterClientScriptBlock(typeof(Common), "showalert", sb.ToString(), true);
        }

So how do I use this method under update panel

Answer

Pranay Rana picture Pranay Rana · Aug 5, 2011

Make use of : ScriptManager.RegisterClientScriptBlock Method

ScriptManager.RegisterClientScriptBlock(
            this,
            typeof(Page),
            "TScript",
            script,
            true);