Panel visible = true无效

时间:2022-07-04 17:08:53

I have a Panel that I'm setting visible=true explicitly. The debugger passes over that line and visible still evaluates to False on the next line. Obviously as a result, the Panel is not shown. How is this possible?

我有一个Panel,我明确设置visible = true。调试器遍历该行,并且在下一行可见仍然评估为False。显然,小组没有显示。这怎么可能?

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 other threads or wonky errata that "should" be messing with my members.

ASP.NET 2.0,没有其他线程或简单的勘误表“应该”弄乱我的成员。

3 个解决方案

#1


47  

Is your panel nested inside another panel or any other type of container which has Visible set to false?

您的面板是否嵌套在另一个面板或Visible设置为false的任何其他类型的容器中?

For such a situation the behaviour your observed is reproducable. It would make sense to forbid to set visibility to true for the inner container if an outer container is invisible since that means nothing inside must be visible, even not the empty div of the inner panel.

对于这种情况,您观察到的行为是可重现的。如果外部容器是不可见的,那么禁止将内部容器的可见性设置为true是有意义的,因为这意味着内部任何内容都不可见,甚至不是内部面板的空div。

The Visible property seems to be dependent on the visibility of outer containers, for instance:

Visible属性似乎取决于外部容器的可见性,例如:

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

This code is as expected (make outer container visible first, then inner container):

此代码符合预期(首先使外部容器可见,然后是内部容器):

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

This code is somewhat surprising (make inner container visible first, then outer container):

这段代码有点令人惊讶(首先使内部容器可见,然后是外部容器):

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

It seems that setting and getting the Visible property is "asymmetric": The Setter seems to place a flag in the control, but the Getter to return a calculated value which depends on the visibility of the outer elements and the visibility of the control itself.

似乎设置和获取Visible属性是“非对称的”:Setter似乎在控件中放置一个标志,但Getter返回一个计算值,该值取决于外部元素的可见性和控件本身的可见性。

Not sure if this will help you at all.

不确定这对你是否有帮助。

#2


0  

By default panel has no border. Your panel is there you are just not seeing it because it is empty. Set borderwidth="1" and you will see your empty panel.

默认情况下,面板没有边框。你的面板在那里,你只是没有看到它,因为它是空的。设置borderwidth =“1”,您将看到空面板。

#3


0  

Problem solved: Panel became visible when I removed visible="false" from child controls.

问题解决了:当我从子控件中删除visible =“false”时,Panel变得可见。

#1


47  

Is your panel nested inside another panel or any other type of container which has Visible set to false?

您的面板是否嵌套在另一个面板或Visible设置为false的任何其他类型的容器中?

For such a situation the behaviour your observed is reproducable. It would make sense to forbid to set visibility to true for the inner container if an outer container is invisible since that means nothing inside must be visible, even not the empty div of the inner panel.

对于这种情况,您观察到的行为是可重现的。如果外部容器是不可见的,那么禁止将内部容器的可见性设置为true是有意义的,因为这意味着内部任何内容都不可见,甚至不是内部面板的空div。

The Visible property seems to be dependent on the visibility of outer containers, for instance:

Visible属性似乎取决于外部容器的可见性,例如:

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

This code is as expected (make outer container visible first, then inner container):

此代码符合预期(首先使外部容器可见,然后是内部容器):

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

This code is somewhat surprising (make inner container visible first, then outer container):

这段代码有点令人惊讶(首先使内部容器可见,然后是外部容器):

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

It seems that setting and getting the Visible property is "asymmetric": The Setter seems to place a flag in the control, but the Getter to return a calculated value which depends on the visibility of the outer elements and the visibility of the control itself.

似乎设置和获取Visible属性是“非对称的”:Setter似乎在控件中放置一个标志,但Getter返回一个计算值,该值取决于外部元素的可见性和控件本身的可见性。

Not sure if this will help you at all.

不确定这对你是否有帮助。

#2


0  

By default panel has no border. Your panel is there you are just not seeing it because it is empty. Set borderwidth="1" and you will see your empty panel.

默认情况下,面板没有边框。你的面板在那里,你只是没有看到它,因为它是空的。设置borderwidth =“1”,您将看到空面板。

#3


0  

Problem solved: Panel became visible when I removed visible="false" from child controls.

问题解决了:当我从子控件中删除visible =“false”时,Panel变得可见。