Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2006, 11:50 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default How to access master page in subdirectory?

I would think this should be easy-but not sure how to fix.

I have a site I'm creating that will use a masterpage. I created an Admin folder for some pages that I want limited access to. These are contentpages that will use the master in the general directory.

My problem is I don't know how to link the content pages in the admin folder to the CSS file and site images that are in the main directory. I was able to copy the css file and the "Site_Images" folder and put in the Admin folder and all worked.

Now, in my master page, I have tinkered with links. Originally, they were all specific to the main folder (ex: <link href="main.css" rel="stylesheet" type="text/css" /> )

I changed this to "/main.css" and "~/main.css". when I do that, the contentpages outside the admin folder can't find the file nor can the pages in the same directory as the master.

Not sure how to solve this so that admin folder can use master page outside the folder the content page is in?

Regards,
Rob

 
Old November 26th, 2006, 12:13 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Ok..I fixed this on my own--but not sure why this works.

I added "runat=server" into the <HEAD> tag.

??
Thanks,
Rob

 
Old November 26th, 2006, 12:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

With a runat="server" attribute, paths like this:

~/Main.css

are expanded to the proper application's root folder at run-time. So, if you have an app called MyApp, then ~/Main.css will expand to:

http://localhost/MyApp/Main.css

This path works from all pages in your site, as it's root relative.

/Main.css won't work as it points to http://localhost/Main.css.
~/Main.css won't work without the runat attribute because you'll end up with this in the browser:

http://localhost/~Main.css

which obviously isn't a valid path.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 26th, 2006, 01:20 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

As always, thanks alot!

Kind Regards,
Rob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Master Page Method: Code-Behind for Content Page kwilliams ASP.NET 2.0 Professional 3 June 2nd, 2008 12:57 PM
Master Page and Content Page with Java script Harjinder ASP.NET 2.0 Professional 1 February 1st, 2008 10:31 AM
master page and content page interaction mrjoka ASP.NET 2.0 Basics 0 March 15th, 2007 10:45 AM
Access Master page control from Content page. angshujit ASP.NET 2.0 Basics 3 January 11th, 2007 06:20 AM
Subdirectory pointing page in main directory vivek_inos ASP.NET 2.0 Basics 2 December 4th, 2006 03:09 AM





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