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
Make use of : ScriptManager.RegisterClientScriptBlock Method
ScriptManager.RegisterClientScriptBlock(
this,
typeof(Page),
"TScript",
script,
true);
const string scriptString = "<script type='text/javascript'> alert('message');</script>";
ClientScriptManager script = Page.ClientScript;
script.RegisterClientScriptBlock(GetType(), "randomName", scriptString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With