我有一個單選按鈕(在updatepanel中)和checkchanged事件我正在向用戶顯示一條消息。但div在masterpage中,頁面沒有渲染,這就是爲什麼我不能顯示消息。 可以解決這個問題嗎?順便說一句我正在使用類來顯示消息。 這是我的代碼。爲什麼我無法在類的updatepanel頁面中顯示js錯誤警報?
public static void setError(System.Web.UI.Page p, string title, string error, string type)
{
Literal literal = p.Master.FindControl("ltMessage") as Literal;
if (type == "error")
{
literal.Text = "<div id=\"alertError\" style=\"display:none; color:#fff; text-align:center; padding: 8px 10px 9px; width:auto; position:relative; background:#cc0000;\"><h3>" + title + "</h3><p>" + error + "</p></div>";
//literal.Text = "<div id=\"alert\" class=\"error message\"><h3>" + title + "</h3><p>" + error + "</p></div>";
StringBuilder sb = new StringBuilder();
sb.Append("$(function() { ");
sb.Append(" $('#alertError').toggle({");
sb.Append(" width: 400");
sb.Append(" });");
sb.Append("});");
if (HttpContext.Current.CurrentHandler is Page)
{
Page pa = (Page)HttpContext.Current.CurrentHandler;
if (ScriptManager.GetCurrent(pa) != null)
{
ScriptManager.RegisterStartupScript(pa, typeof(Page), "alert", sb.ToString(), true);
}
else
{
pa.ClientScript.RegisterClientScriptBlock(typeof(Page), "alert", sb.ToString(), true);
}
}
}
}