Solved

BasePage properties sometimes there, sometimes not.

Posted on 2013-01-30
6
203 Views
Last Modified: 2013-02-05
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
0
Comment
Question by:SeanNij
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Assisted Solution

by:Eduard Ghergu
Eduard Ghergu earned 500 total points
ID: 38834842
Hi,

You're neglecting the stateless nature of the web. Try something like:

public bool ShowHeadersAndFooters
    {
        get { return (bool)Session["ShowHeadersFooters"]; }
        set { Session["ShowHeadersFooters"] = value; }
    }
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38835997
@seanNij,

Where are you setting your ShowHeadersAndFooters properties? By default it's false.
You must set them somewhere on your page.
0
 
LVL 1

Accepted Solution

by:
SeanNij earned 0 total points
ID: 38839089
Hi,

Thanks for the reply.

It did not work, however you did give me an idea, ghergu.

So what I've done is this:

In my aspx.cs file I did:

    protected void Page_Init(object sender, EventArgs e)
    {
        Session["ShowHeadersAndFooters"] = false;
    }

Open in new window


and in my master.cs I did:

    protected void Page_Load(object sender, EventArgs e)
    {
            if (Session["ShowHeadersAndFooters"] != null)
                bShowHeadersAndFooters = (bool)Session["ShowHeadersAndFooters"];
    }

Open in new window


Works like a charm!
Thanks for the idea!
S
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Eduard Ghergu
ID: 38839115
Hi!
You're welcome! Any "reward" for this?
0
 
LVL 1

Author Comment

by:SeanNij
ID: 38839130
@ghergu Close Request Pending. Points awarded to you. Will close auto on 02/04/2013 if no objections.
0
 
LVL 1

Author Closing Comment

by:SeanNij
ID: 38854270
First answer gave me an idea and created my own solution. Point still awarded to the person who gave me the idea.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question