面板可见性javascript

时间:2011-01-25 10:13:03

标签: asp.net

<asp:Panel ID="FilterPanel" runat="server" CssClass="FilterBorder" 
                      Visible="false">
<table width="100%" cellspacing="4">
        <tr>
            <td class="FilterPanelFilterControlWidth">
        <Uc:Filter ID="Filter" runat="server" />
    </td>
    <td class="CenterInCell">
        <Controls:BrButton ID="GoButton" runat="server" Text="Go" 
                   CausesValidation="true" SkinID="VerySmallButton" 
                   OnClick="GoButton_Click" />
    </td>
    </tr>
   </table>
</asp:Panel>

我将我的过滤器面板的可见性设置为false ..默认情况下..

点击显示/隐藏过滤器我想将其更改为visible = true。 我正在通过javascript ..喜欢这个

function showHideFilter() {
    if (document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterShowHideHiddenField').value == 'true') {
        document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterPanel').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterPanel').style.visibility = 'hidden';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterShowHideHiddenField').value = 'false';
        return false;
    }
    else {
        document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterPanel').style.display = 'inline';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterPanel').style.visibility = 'visible';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterShowHideHiddenField').value = 'true';
        return false;
    }
}

然而,因为ethe visible设置为false ..我得到这样的运行时错误 required对象设置为null..below ..

document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterPanel').style.display = 'inline';

document.getElementById('ctl00_ContentPlaceHolder1_ctl00_FilterPanel').style.visibility = 'visible';

我哪里错了.. !!

1 个答案:

答案 0 :(得分:1)

visible="false"runat="server"时,该对象不会从服务器发送到客户端。因此,您无法通过javascript将其显示,您需要在服务器上执行此操作。