tags:

views:

103

answers:

3

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

+1  A: 

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.

slolife
A: 

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.

CRice
+2  A: 

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

kaneuniversal
Why are you writing the designer.cs file by hand? And also, how are you writing it by hand. I thought it gets overwritten by the VS code-generator?
Dan Herbert
The visual designer is slow and I'm getting into jQuery more and more, and shying away from server controls that require ViewState. VS *does* overwrite my code (if I ever open a file in the visual designer), but since I'm only declaring page controls and not writing functions, it doesn't matter.
kaneuniversal