<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
    function test()
    {
      var my_div=document.getElementById("DIV1"); 
      var _div=document.createElement("div"); 
      _div.innerText=<%=my_value %>;
      my_div.appendChild(_div);
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="DIV1"></div>
    <input type="button" value="页面传值" onclick="test()"/>
    </div>
    </form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page 
{
    public string my_value = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        my_value = "gfdgfdgfd";
    }
}

解决方案 »

  1.   

     _div.innerText= "<%=my_value %>";
      

  2.   

    嗯 问题解决了  +分 
    顺便问一下为什么有的时候_div.innerText的值为null 而不是my_value 的值
    但是调试的时候显示<%=my_value %>的值为my_value 
      

  3.   

    my_value值在客户端打开页面的时候就已经传到了客户端,接下来就是js赋值的事情了,我们知道js很不稳定,不同的浏览器,不同的机器,不同的时间都有可能产生不同的结果,所以偶尔发生赋值不成功,也是正常的。