我在网页中加入一个web用户控件,运行时控件js函数ShowMList总提示错误“缺少对象”,getElementById取不到值。
如何解决啊,请指教,多谢了!web控件如下:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<link href="MyStyles.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript">         
        var timoutID;
    function ShowMList()
    {
        var divRefC = document.getElementById("divCheckBoxListClose");
        divRefC.style.display = "block";
        alert('aafdfdf');
    }
    
    function HideMList()
    {
        document.getElementById("divCheckBoxListClose").style.display = "none";   
    }     
            </script><asp:ScriptManager ID="smDefault" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upDefault" runat="server">
    <ContentTemplate>
        &nbsp;<br />
        <div id="divCustomCheckBoxList" runat="server" onmouseout="timoutID = setTimeout('HideMList()', 750);"
            onmouseover="clearTimeout(timoutID);">
            <table>
                <tr>
                    <td align="left" class="DropDownLook">
                        <img id="imgShowHide" runat="server" alt="选择" align="left" onclick="ShowMList()" src="drop.gif" />
                    </td>
                </tr>
                <tr>
                    <td class="DropDownLook" colspan="2">
                        <div>
                            <div id="divCheckBoxListClose" runat="server" class="DivClose">
                                <label id="lblClose" runat="server" class="LabelClose" onclick="HideMList();" style="left: 213px;
                                    bottom: 0px; width: 34px;">
                                    确定</label>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <div>
            <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit Selection" />
            <br />
            <br />
            <asp:Label ID="lblTextSelected" runat="server" Font-Bold="true" Text=""></asp:Label>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

解决方案 »

  1.   

    楼上的是什么意思?主页面就加了个控件<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %><!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>
        <link href="MyStyles.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <uc1:WebUserControl ID="WebUserControl1" runat="server" />
        
        </div>
        </form>
    </body>
    </html>
      

  2.   

    <div id="divCheckBoxListClose" runat="server" class="DivClose"> "DivClose"在这个样式中你是不是先隐藏了 你试试不隐藏还报错吗
      

  3.   

    多谢2楼的兄弟,加上控件后id变成这个了:WebUserControl1_divCheckBoxListClose感谢,结贴