Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 18th, 2008, 06:31 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

Reply With Quote
  #2 (permalink)  
Old January 19th, 2008, 12:28 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old January 21st, 2008, 04:58 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #4 (permalink)  
Old January 22nd, 2008, 10:33 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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

-Peter
Reply With Quote
  #5 (permalink)  
Old January 22nd, 2008, 03:06 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.



Reply With Quote
  #6 (permalink)  
Old January 22nd, 2008, 03:38 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
Reply With Quote
  #7 (permalink)  
Old January 22nd, 2008, 03:46 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #8 (permalink)  
Old January 23rd, 2008, 04:27 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #9 (permalink)  
Old January 23rd, 2008, 12:25 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #10 (permalink)  
Old January 23rd, 2008, 01:20 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Footer only for last page XSLTUser XSLT 0 December 27th, 2007 04:34 PM
page footer drachx Crystal Reports 0 October 12th, 2005 05:47 AM
Sorting based on formula in group footer NixyJ Crystal Reports 0 August 27th, 2004 06:37 AM
suppress Page footer in some pages cankalu Crystal Reports 1 June 4th, 2004 10:15 AM
page footer damnnono_86 Access 8 October 27th, 2003 09:16 PM



All times are GMT -4. The time now is 04:30 PM.


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