Alert(ex.ToString(), UpdatePanel1) 这样为什么显示不了?
Alert("出错了"), UpdatePanel1) 这样就行public static void Alert(string _Msg, UpdatePanel UP_Name)
{
//顯示提示信息
System.Web.UI.ScriptManager.RegisterClientScriptBlock(UP_Name, typeof(UpdatePanel), "AjaxMsgBox", "alert('" + _Msg + "');", true);
}
System.Web.UI.ScriptManager.RegisterClientScriptBlock(UP_Name, typeof(UpdatePanel), "AjaxMsgBox", "alert('" + ex.ToString() + "');", true);
那么你使用那个UpdatePanel的实例作为参数都可以;如果每个UpdaePanel的UpdateMode=conditional,
你必须使用正在更新的那个UpdatePanel作为参数,这样脚本才能起作用。
ex.ToString() 里包含了一些引号,括号之类的东西,这样导致你alert()时JS出错,你可以用在
System.Web.UI.ScriptManager.RegisterClientScriptBlock
前面加上一句Response.Write 把ex.ToString()输出来观察下
你这里的ex是什么?
如果是try..catch块里的(Exception ex)
那得这样写:
ex.Message.ToString()
Alert(ex.ToString(), UpdatePanel1)
public static void Alert(string _Msg, UpdatePanel UP_Name)
{
//顯示提示信息
System.Web.UI.ScriptManager.RegisterClientScriptBlock(UP_Name, GetType(UpdatePanel), "AjaxMsgBox", "alert( _Msg );", True);
}這樣還是不行
是不是要把string _Msg 改為 Exception _Msg
Alert(ex.ToString(), UpdatePanel1)這里是這樣調用的嗎?
Alert(straa, UpdatePanel1) Public Sub Alert(ByVal _Msg As String, ByVal UP_Name As UpdatePanel)
'顯示提示信息
System.Web.UI.ScriptManager.RegisterClientScriptBlock(UP_Name, GetType(UpdatePanel), "AjaxMsgBox", "alert('" & _Msg & "');", True)
End Sub這樣也不行。。暈
Alert(ex.ToString(), UpdatePanel1) 改成Alert(ex.Message.ToString(), UpdatePanel1)
试试