views:

303

answers:

4

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?

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>

alt text

ASP.NET 2.0, no other threads or wonky erratta that "should" be messing with my members.

A: 

Panel became visible when I removed visible="false" from child controls. Now can anyone tell me why an empty Panel can't be visible?

tsilb
Something else must be setting it's visibilty or the debugger is going wonky. Do you see a <div> in your rendered HTML with the client ID of this panel? If so, it's there.
nickyt
@nickyt: Remember that setting and getting a property is not assigning a value to a public data field in an object. It is calling methods; there is no guarantee that the method for "get" returns the same value you've set with "set".
Slauma
A: 

Because empty panel is not needed?

wRAR
A: 

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.

Matt
But pnlValidate.Visible = false
tsilb
A: 

Is your panel nested inside another panel or any other type of container which has Visible set to 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.

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

<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.

Not sure if this will help you at all.

Slauma