显示/隐藏面板不工作在用户控制

Show/Hide panel not working in usercontrol

本文关键字:工作 用户 控制 隐藏 显示      更新时间:2023-09-26

我试图显示/隐藏面板时,用户单击按钮。当我将这段代码粘贴到.aspx页面中时,一切都工作正常,但如果这段代码在usercontrol中,则无法工作。有什么建议吗?代码:

<script type="text/javascript">
    function ShowHideOne() {
        if (document.getElementById('<%=CommentPanel.ClientID %>').style.display == "none") {
            document.getElementById('<%=CommentPanel.ClientID %>').style.display = "block";
        }
        else {
            document.getElementById('<%=CommentPanel.ClientID %>').style.display = "none";
        }
        return false;
    } </script>
    <asp:Button ID="btnShowComments" runat="server" Text="Comments" OnClientClick="javascript:return ShowHideOne();"/>      
    <asp:Panel ID="CommentPanel" runat="server">
        ToDo: COMMENTS!
    </asp:Panel>

您的代码在usercontrol中仍然正常工作

使用

<asp:Button ID="btnShowComments" runat="server" Text="Comments" OnClientClick="ShowHideOne();"/>