当前位置: 代码迷 >> ASP.NET >> panel 暗藏不了
  详细解决方案

panel 暗藏不了

热度:7275   发布时间:2013-02-25 00:00:00.0
panel 隐藏不了
在 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 下放了panel控件
  <asp:Panel ID="Panel1" HorizontalAlign="Center" runat="server" 
  Height="16px" Visible="False" Width="210px">
  </asp:Panel>

在后台 Panel1.Visible=true; 可以显示出来 但是Panel1.Visible=false 却不能隐藏。我换成调用脚本的方式
function ClosePanel()
 {
 document.getElementById('Panel1').style.display='none';
 }

也不能隐藏。 请问 有谁知道这是怎么回事嘛? 谢谢!



------解决方案--------------------------------------------------------
可以的,我试了下
HTML code
 <asp:ScriptManager ID="ScriptManager1" runat="server">        </asp:ScriptManager>        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />        <br />        <asp:UpdatePanel ID="UpdatePanel1" runat="server">            <ContentTemplate>                        <asp:Panel ID="Panel1" runat="server">                        123                        </asp:Panel>            </ContentTemplate>        </asp:UpdatePanel>
------解决方案--------------------------------------------------------
EnablePartialRendering设置false会向传统网页一样全部刷新画面,true的时候是部分刷新,
你该不会是EnablePartialRendering这只true,然后只有按钮放到了updatepanel中,panel没有在updatepanel中吧?那种事不会刷新的,你需要把panel也放进去
------解决方案--------------------------------------------------------
首页后台代码不能隐藏可能是你代码的问题,可以贴出来看看。脚本你获取方式有误
document.getElementById('<%=Panel1.ClientID%>').style.display='none';
 
------解决方案--------------------------------------------------------
你的JS有问题,你的Panel服务器控件,
应该这么写
JScript code
function ClosePanel() { document.getElementById('<%=Panel1.ClientID%>').style.display='none'; }
------解决方案--------------------------------------------------------
lz 在后台用Visible = false是可以隐藏的,你看看你的Panel是否放在了UpdatePanel的项模板下
 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
能否隐藏
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="测试" 
onclick="Button1_Click1" />
</ContentTemplate>
</asp:UpdatePanel>
------解决方案--------------------------------------------------------
Panel1.Visible=false 必须在后台设置,并且确保你在updatepanel中的更改Visible的代码确实被触发执行了。还有就是楼上提到的,是不是ID错了(感觉应该不会是这个问题吧....)。
------解决方案--------------------------------------------------------
LZ把你的代码全部贴出来,
1.UpdatePanel的问题——把它删除再调试一下
2.JS的问题 -- 可能是页面周期问题
------解决方案--------------------------------------------------------
JScript code
   window.onload = function(){                document.getElementById('<%=Panel1.ClientID%>').style.display='none';   };