p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Footer Image Based on Current Page (http://p2p.wrox.com/showthread.php?t=65360)

gothael January 18th, 2008 06:31 PM

Footer Image Based on Current Page
 
I've got a Master page that displays a footer image. I'd like to have a different footer image displayed based on if you are on the home page. Any ideas how to determine if you are on the home page of your site when using Master pages?


planoie January 19th, 2008 12:28 PM

If you are using the web application project (compiled app) then you can test the class type of the current page against that of the home page. Let's say your home page is "homepage.aspx", the codebehind class would be "homepage" so you can test it like this:

isHomePage = this.Page is homepage; // C#
   or
isHomePage = TypeOf Me.Page Is homepage 'VB

If you are using the web site project type you'll have to test the page url. I don't have VS in front of me at the moment, but it's something like this:

isHomePage = this.Page.Request.Url.ToLower().Contains("homepage .aspx"); // C#

isHomePage = Me.Page.Request.Url.ToLower().Contains("homepage.a spx") ' VB


-Peter

gothael January 21st, 2008 04:58 PM

I tried the following in my Master page's code behind, but it won't compile:

protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Page is Default)
        {
            imgPageBottom.ImageUrl = "images/footer_home.gif";
        }
    }

I am getting "The type or namespace name "_Default" could not be found. The class name of my home (content) page appears to be "_Default":

public partial class _Default : System.Web.UI.Page

Maybe I've got they syntax wrong? Thanks for the reply, by the way.


planoie January 22nd, 2008 10:33 AM

Change:
   this.Page is Default
to
   this.Page is _Default

-Peter

gothael January 22nd, 2008 03:06 PM

I changed to _Default, but I still get the same type of error. Does _Default need to be in quotes or anything like that? Site.Master.cs doesn't seem to see that Default.aspx.cs has _Default defined.




planoie January 22nd, 2008 03:38 PM

What project type are you using? Web site project (Out of the box behavior of VS2005) or web app project? If you aren't sure then you are probably using the web site project type. In that case you can not do type checks because the types are not compiled together. You'll have to use the technique I described earlier using the URL check.

-Peter

gothael January 22nd, 2008 03:46 PM

I'll try to create a new web app project. I didn't know there was a difference in creating sites in .NET Thank you.


weicco January 23rd, 2008 04:27 AM

Just check the page from Request.Url and you're fine.


gothael January 23rd, 2008 12:25 PM

I thought about that, but I've been naming all the "index" files in each directory Default.aspx. Wouldn't this make it a little tricky to try and pin down whether you are on the home page?


planoie January 23rd, 2008 01:20 PM

The URL will include the directory so:

/Default.aspx == home page
/admin/Default.aspx == administration home page
/widgets/Default.aspx == Widgets home page

and so on.

-Peter


All times are GMT -4. The time now is 12:55 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.