很简单的一个问题,我要在catch语句块中要通过Response.Write方法打印出捕获的异常:
catch (Exception exp)
{
    string expMsg = exp.ToString();
    Response.Write("<Script> alert(...) </script> ");
}里面的Script语句应该怎么写呢?

解决方案 »

  1.   

    Response.Write("<Script> alert('"+expMsg+"'); </script> ");
      

  2.   

    Response.Write("<Script> alert('" + exp.ToString() + "'); </script> ");哎,快要疯了,这样写没错吧!怎么可以出错呢?下边是错误信息:
    网页错误详细信息
    消息: 缺少 ')'
    行: 1
    字符: 65
    代码: 0
    URI: 保密
      

  3.   

    ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript'>alert('" + ex.Message+ "');</script>");
      

  4.   

    Response.Write("<Script> alert('" + exp.ToString() + "'); </script> ");
    改成Response.Write("<script> alert('" + exp.ToString() + "'); </script> ");
    js区分大小写
      

  5.   

     Response.Write("<Script> alert('"+exp+"') </script> ");
      

  6.   

    Response.Write("<script> alert('"+exp+"') </script> ");
      

  7.   

    可能你的要打印的错误信息里含有')"或单引号之类的,这样写是没有错的,建议你改成这样试一下Response.Write("<script>alert('"+Server.HtmlEncode(expMsg.Replace("'","\'"))+"'); </script> ");
      

  8.   


    ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript'>alert('" + ex.Message+ "');</script>");
      

  9.   

    csdn的asp.net论坛还有asp.net程序员吗?不会都是javascript程序员吧。
      

  10.   

    其实,这个问题是因为HTML解析器不理解JavaScript代码,如果它看到代码中的"</script>"字符串,即使该字符串标记出现在引号中,HTML解析器也会认为它发现了当前运行的脚本的结束标记,要避免这种问题,只需要将标记拆成片段,用表达式"</"+"script>"写即可,活着是用多条Response.write()将字符串拆开链接。另外,还可以在</script>中用转义字符'\':Response.Write("<\/script");在XHTML中,脚本包含在CDATA部分中,这一使用结束的</script>标记的问题不会发生。