Panel visible = true no tiene efecto


Tengo un Panel que estoy configurando visible=true explícitamente. El depurador pasa por encima de esa línea y visible todavía se evalúa a False en la siguiente línea. Obviamente, como resultado de ello, no se muestra el Grupo. ¿Cómo es esto posible?

pnlValidate.Visible = true;
if (IsPostBack) return;
<asp:Panel ID="pnlValidate" runat="server">
    <asp:Button cssclass="submit2" ID="btnValidate" runat="server" Visible="false" text="Validate" OnClick="btnValidate_Click" /> <br />
    <asp:TextBox ID="txt6sql" runat="server" Visible="false" TextMode="multiLine" Width="500" Height="200" ReadOnly="true" ToolTip="Report SQL Statement" />
</asp:Panel>

ASP.NET 2.0, no hay otros hilos o erratas torcidas que "deberían" estar jugando con mis miembros.

Author: Michael, 2010-03-29

3 answers

¿Está su panel anidado dentro de otro panel o cualquier otro tipo de contenedor que tenga Visible establecido en false?

Para tal situación el comportamiento observado es reproducible. Tendría sentido prohibir establecer visibilidad en true para el contenedor interno si un contenedor externo es invisible, ya que eso significa que nada en el interior debe ser visible, incluso no el div vacío del panel interno.

La propiedad visible parece depender de la visibilidad de los contenedores exteriores, para instancia:

<asp:Panel ID="Panel0" runat="server" Visible="false">
    <asp:Panel ID="Panel1" runat="server" Visible="false">
        Content...
    </asp:Panel>
</asp:Panel>

Este código es el esperado (hacer visible primero el contenedor exterior, luego el contenedor interior):

Panel0.Visible = true;
// Now Panel0.Visible returns true and Panel1.Visible returns false
Panel1.Visible = true;
// Now Panel0.Visible returns true and Panel1.Visible returns true

Este código es algo sorprendente (hacer visible primero el contenedor interior, luego el contenedor exterior):

Panel1.Visible = true;
// Now Panel1.Visible returns false (!, your issue) and Panel0.Visible returns false
Panel0.Visible = true;
// Now Panel1.Visible returns true (!!) and Panel0.Visible returns true

Parece que establecer y obtener la propiedad Visible es "asimétrica": El Setter parece colocar una bandera en el control, pero el Getter para devolver un valor calculado que depende de la visibilidad de los elementos exteriores y la visibilidad de control sí mismo.

No estoy seguro de si esto te ayudará en absoluto.

 51
Author: Slauma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-29 18:29:51

Por defecto el panel no tiene borde. Su panel está allí, simplemente no lo ve porque está vacío. Establezca borderwidth= " 1 " y verá su panel vacío.

 0
Author: Matt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-29 16:48:29

Problema resuelto : El panel se hizo visible cuando eliminé visible="false" de los controles hijos.

 0
Author: tsilb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-10 00:24:08