Link to home
Start Free TrialLog in
Avatar of SeanNij
SeanNijFlag for South Africa

asked on

BasePage properties sometimes there, sometimes not.

Hi All,

I have been searching like crazy but can't seem to get the answer I want.

I have a ASP.NET 2.0 project.
I inherit a BasePage called DefaultBasePage to check whether user is logged in.
Also uses properties in this page to check on my master page if I should display the menu or not.
I've got 2 pages here that are exactly the same with regards to this, but one of the pages gets the value from the base page and the other doesn't.

Here is my DefaultBasePage.cs

public class DefaultBasePage : System.Web.UI.Page
{
    private bool bShowHeadersFooters;
    private bool bNeedsToBeLoggedIn = true;

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        if (Session["ID"] == null
            && !Request.Url.ToString().Contains("login.aspx")
            && bNeedsToBeLoggedIn)
        {
            Response.Redirect(Application["URL"] + "login.aspx?ReturnUrl=" + Server.UrlEncode(Request.Url.ToString()));
        }
    }
    public bool ShowHeadersAndFooters
    {
        get { return bShowHeadersFooters; }
        set { bShowHeadersFooters = value; }
    }

}

Open in new window


DefaultMaster.master.cs

        if (Page is DefaultBasePage)
        {
            bShowHeadersAndFooters = ((DefaultBasePage)Page).ShowHeadersAndFooters;
            if (Session["ID"] != null)
            {
                if (bShowHeadersAndFooters)
                {
// Show Menu. Works sometimes and sometimes not.
}
}
}

Open in new window


Any ideas would be greatly appreciated as I am banging my head against the wall because of this,

Thanks in advance,
S
SOLUTION
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@seanNij,

Where are you setting your ShowHeadersAndFooters properties? By default it's false.
You must set them somewhere on your page.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi!
You're welcome! Any "reward" for this?
Avatar of SeanNij

ASKER

@ghergu Close Request Pending. Points awarded to you. Will close auto on 02/04/2013 if no objections.
Avatar of SeanNij

ASKER

First answer gave me an idea and created my own solution. Point still awarded to the person who gave me the idea.