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.
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);
}
}
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
精彩评论