tryResponse.Write("<body onload=init('on','" + t + "')>"); 

解决方案 »

  1.   

    思归大侠,不行啊,只要加上HTML标签就出错,Response.Write("<body onload=init('on','<h1>hello<h1>')>");
    这样就出错。是不是JS代码的问题?我把JS代码检查了好几遍就是没找出什么地方出错了。
    以下是这段JS代码:function init(Model,Html) 
    {

    Editor.document.designMode=Model;
    if(Html !="")
    initHTML = Html;
    Editor.document.open();
    Editor.document.write(initHTML);
    Editor.document.close();

    initHTML = "";}怎么会这么奇怪?
      

  2.   

    咋把俺给晾着了?思归?imfine?去哪了?俺把全部家底都押上求个解成不?
      

  3.   

    Page_Load中可以改变<body>的内容吗?
      

  4.   

    add a "" around init(....):<script language="C#" runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
       if(!Page.IsPostBack)
       {
          string t = "<h1>hello</h1>";
          Response.Write("<body onload=\"init('on','" + t + "')\">"); 
       }
    }
    </script>
    <script language="javascript">
    function init(a,b)
    {
     alert(a);
     alert(b);
    }
    </script>
      

  5.   

    思归大侠,还是不行,这是不是C#的一个BUG呢?看看以下的结果:function init(Model,Html) 
    {

    Editor.document.designMode=Model;
    if(Html !="")
    initHTML = Html;
    Editor.document.open();
    Editor.document.write(initHTML);
    Editor.document.close();

    initHTML = "";}在Load_Page中
    Response.Write("<body onload=init('on','hello')>");//可以运行Response.Write("<body onload=init('on','<H1>hello</H1>')>");//不能运行string t = "hello";
    Response.Write("<body onload=\"init('on', + t + ")\">");//不能运行
    如果将Response.Write("<body onload=\"init('on', + t + ")\">");
    改为:Response.Write("<body onload=init('on', '')>");将function init(Model,Html)中的:Editor.document.write(initHTML);
    改为:Editor.document.write('<H1>hello</H1>');
    就可以运行正常,看来问题好象不在javascript上,而是C#中无法用Response.Write方法将变量赋给客户端,为什么会出现这种情况?真的是搞不懂。有没有替代的其它办法将服务器控件值赋给指定的客户端对象中?
      

  6.   

    string t = "<h1>hello</h1>";
    Response.Write("<body onload=\"init('on','" + t + "')\">"); 
                                ^^^^        ^^^^      ^^^^^^
    ortrystring t = "<h1>hello</h1>";
    Response.Write("<body onload=\"init('on',dvhtml.innerHTML)\">");
    Response.Write("<div id='dvhtml' style='display:none'>" + t + "</div>");