Reputation: 38248
I have copy and paste this Alert Class: http://madskristensen.net/post/JavaScript-AlertShow%28e2809dmessagee2809d%29-from-ASPNET-code-behind.aspx
It works except with a button inside an update panel but it shows no error. The asp code inside is executed but nothing shows up on client side.
Upvotes: 2
Views: 209
Reputation: 17589
I suggest not to use updatePanels at all, implement scriptable webservice and access it via proxy kindly generated for you by asp.net it will save you tons of nerves as well as time, because updatepanel is really really buggy
Upvotes: 1
Reputation: 37516
Registering the Javascript with ScriptManager.RegisterClientScriptBlock
rather than page.ClientScript.RegisterClientScriptBlock
will take care of registering scripts during partial page updates. Here's the modified code:
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 = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
ScriptManager.RegisterClientScriptBlock(page, typeof(Alert), "alert", script, false);
}
}
Upvotes: 1