marclar
marclar

Reputation: 3046

Invisible controls still being rendered

I'm having the weirdest problem.

I have two PlaceHolders in a Master Page; one contains controls for users who are logged-out, and the other for users who are logged-in.

They are:

plhLoggedOut

plhLoggedIn

During my Page_Load (of the Master Page), I set their visibility like so:

        //LOGGED-IN?
        plhLoggedOut.Visible = (app.UserID == 0);
        plhLoggedIn.Visible = (app.UserID != 0);

However, the contents of BOTH PlaceHolders are still being rendered.

I'm even writing their visibility to a status message, and that status message confirms that only one is visible at any given time. e.g.,

plhLoggedOut.Visible == True; plhLoggedIn.Visible == False  

Any ideas how this could happen (and how to fix it)?

Thanks very much,

Michael

Upvotes: 1

Views: 347

Answers (3)

marclar
marclar

Reputation: 3046

I just removed the old PlaceHolders and created two new ones with different IDs. Then it started working.

I vaguely remember having weird behaviors like that before, where for some reason the code-behind and the markup are disconnected. That might happen because I don't use the visual designer, and write the .NET tags and the designer.cs file by hand.

FYI, slolife, I just tested it and visibility doesn't get passed down like that from parent controls to child controls. You can nest a hidden control that remains hidden even if you set its container's visibility to true.

Thanks, everyone,

Michael

Upvotes: 2

CRice
CRice

Reputation: 12567

You call also try

<asp:PlaceHolder ID="plhLoggedOut" runat="server" Visible="<%# app.UserID == 0 %>" />

<asp:PlaceHolder ID="plhLoggedIn" runat="server" Visible="<%# app.UserID != 0 %>" />

Then databind them to make the expression evaluated.

Upvotes: 0

slolife
slolife

Reputation: 19870

Maybe somewhere else in your code you are setting a parent control of those panels to visible, which rips through all children and sets them to visible as well. You need to change your code so that plhLoggedOut and plhLoggedIn visibility is set after their parent controls.

Upvotes: 2

Related Questions