给位高手请教下,我在一个下拉列表框的SelectedIndexChanged事件里面用 Page.RegisterClientScriptBlock("s", "<script>DisDiv();</script>");调用这个前台方法,
 function DisDiv() {
              document.getElementById('LoadDiv').style.display = 'block'
          }是一个前台div的显示,可是它就是不出来,也没报错,各位给我个好办法啊,让它能执行出来吧,必须是后台调用前天的方法,且是在UpdatePanel框架里面的 急....

解决方案 »

  1.   

    参考这个:
    http://www.cnblogs.com/insus/articles/1945582.html
      

  2.   

    首先你在前台先加一个按钮调用DisDiv(),看看是否可以找到该控件,证明其存在如果确实存在,后台Page.RegisterStartupScript("script", "<script>DisDiv()</script>");应该可以调用。希望对楼主有帮助
      

  3.   

    如果是用UpdatePanel的话,得用
    ScriptManager.RegisterStartupScript(this, typeof(string), "s", "DisDiv();", true);
      

  4.   

    ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, typeof(UpdatePanel), "test", "DisDiv();", true); 
     
      

  5.   

    ScriptManager.RegisterStartupScript(this, typeof(string), "s", "DisDiv();", true);
      

  6.   

    ScriptManager.RegisterStartupScript(this.UpdatePanel1,this.typeof(), "s", "DisDiv();", true);
      

  7.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            #test{width:100px;height:100px;background-color:#fefef0;display:none;border:1px solid blue;text-align:center;}
        </style>
        <script language="javascript" type="text/javascript">
            function DivDisplay() {
                var oDiv = document.getElementById("test");
                oDiv.style.display = "block";
                var text = document.getElementById("<%=drlCity.ClientID %>").value;
                oDiv.innerHTML = text;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList runat="server" ID="drlCity" AutoPostBack="true" 
                onselectedindexchanged="drlCity_SelectedIndexChanged">
                <asp:ListItem Text="上海" Value="shanghai" />
                <asp:ListItem Text="北京" Value="beijing" />
            </asp:DropDownList>
            <div id="test"></div>
        </div>
        </form>
    </body>
    </html>
            protected void drlCity_SelectedIndexChanged(object sender, EventArgs e)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "display", "DivDisplay()", true);
            }