Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

BasePage properties sometimes there, sometimes not.

Posted on 2013-01-30
6
Medium Priority
?
207 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

660 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