页面代码:
<body>
    <form id="form1" runat="server">
    <div id="divFly" style="border:1px solid black;background:red;width:200px;height:200px;display:none;position:absolute;filter:Alpha(opacity=30)">
        <table width=100% height=100%>
            <tr>
                <td>
                图层可以显示了。
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>后台
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write("<script>document.getElementById('divFly').style.display='block';</script>");
        }
}

解决方案 »

  1.   


    Response.Write输出在页面的最上传下面HTML代码还没加载下来呢,肯定取不到对象
    度下下面代码
    <body> 
        <form id="form1" runat="server"> 
        <div id="divFly" style="border:1px solid black;background:red;width:200px;height:200px;display:none;position:absolute;filter:Alpha(opacity=30)"> 
            <table width=100% height=100%> 
                <tr> 
                    <td> 
                    图层可以显示了。 
                    </td> 
                </tr> 
            </table> 
        </div> <script>document.getElementById('divFly').style.display='block'; </script>
        </form> 
    </body> 
      

  2.   

    还是不行呀。换了下写法
    页面:
    <div id="divFly" style="border:1px solid black;background:red;width:200px;height:200px;display:none;position:absolute;filter:Alpha(opacity=30)">
            <table width=100% height=100%>
                <tr>
                    <td>
                    图层可以显示了1。
                    </td>
                </tr>
            </table>
        </div>       <asp:Button ID="Button1" runat="server" Text="155" OnClick="Button1_Click" />后台:
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>document.getElementById('divFly').style.display='block'</script>");   
    }这样仍然提示“错误:缺少对象”。
    3楼的老大,请问还要怎样注册,才能找到对象啊?
      

  3.   

    这样用的
    ScriptManager.RegisterStartupScript(this, this.GetType(), "ChangeStyle!", "document.getElementById('divFly').style.display='block' ;", true);
      

  4.   

    你这样肯定不行.点击button的时候,你输出那个代码在页面上部,这时候,页面下面的代码还没有加载,div 还没有.肯定找不到对象你可以用html控件,响应onclick这样前端js直接解决了.如果是服务器的button,也可以直接用OnClientClick前端js解决
      

  5.   


    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                Button1.Attributes.Add("OnClick","document.getElementById('divFly').style.display='block'");
            }