日期:2014-05-18  浏览次数:20567 次

在网页中如果用try..catch捕获异常并输出,请问我下面的语句错了么?怎么有异常却没有弹出窗口提示错误
我用了下面两种方法都不行,是不是在网页中捕获异常不能弹出窗口提示异常信息??
C# code

  try
        {
            conn.Open();
            int a = cmd.ExecuteNonQuery();
            if (a == -1)
            {
                Response.Write("<script language=javascript>alert('添加失败');location='javascript:history.go(-1)'</script>");
            }
            else
            {
                //Response.Write("<script language=javascript>alert('添加成功');</script>");
            }
           

        }
        catch(Exception ex)
        {         
           // Response.Write("<script language=javascript>alert('"+ex.ToString()+"');location='Test.aspx'</script>");
            ScriptManager.RegisterStartupScript(udp1, typeof(UpdatePanel), "scriptname", "alert('" + ex.ToString() + "');", true);
        }


------解决方案--------------------
应该是可以的哇
你的网页上有updatepanel这个东西么
有的话,用这个控件是可以的 
没有的话是另外的一个对象

------解决方案--------------------
Page.RegisterStartupScript("clientScript", "<script>alert('没有找到符合条件的数据!')</script>");//代码要写在***.aspx.cs文件中哦
------解决方案--------------------
“有异常却没有弹出窗口提示”

你先说说看,有什么异常?
------解决方案--------------------
在UpdatePanel中 貌似ScriptManager弹出窗口才有效
------解决方案--------------------
C# code

  this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('测试输出!')", true);

------解决方案--------------------
updatepanel里不能用this.GetType(),这里的this是Page,没用的,要用control:

protected void DateTimePicker1_OnDateUpdated(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(DateTimePicker1, DateTimePicker1.GetType(), "abc", "alert('good');", true);
}
------解决方案--------------------
直接挂掉了 还弹什么?