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 October 5th, 2008, 02:33 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default Problem with App root relative paths

I'm having problems in the document head. I have two link tags, one which draws in my favicon. The other draws in my main stylesheet. I defined their paths relative to the application root, but as you can see, in the final HTML output the tilde's survive. In all other cases, the application root relative paths are working beautifully. I will have real problems if I can't get my master page to draw in my stylesheet. The link to the page and code are below. Thanks.

http://beta.earthchronicle.com/ECBet...ngItAllUp.aspx

Here's the .NET code for the two tags...
<link rel="shortcut icon" href="~/ECBeta/Images/favicon.ico" type="image/x-icon" runat="server" />
<link rel="stylesheet" type="text/css" media="all" title="ecstylesheet" href="~/ECBeta/CSS/ecMaster.css" runat="server" />


Here's the HTML output of the two tags...
<link rel="shortcut icon" href="~/ECBeta/Images/favicon.ico" type="image/x-icon"></link>
<link rel="stylesheet" type="text/css" media="all" title="ecstylesheet" href="~/ECBeta/CSS/ecMaster.css"></link>


-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old October 5th, 2008, 09:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Unfortunately, it seems that ASP.NET only automatically processes the ~ replacement for stylesheet links. It's too bad that they put in this behavior at all as it kind of breaks the server control versus literal markup rules. I think they should have created server side tags for this stuff so it is more obvious what you can put in them.

But regardless of that... you can work around this problem. What I often do is wrap all my literal head markup inside an <asp:literal id="litHead"> control. The you could do a manual replacement of the ~ so all your URLs are resolved to the application root:

litHead.Text = litHead.Text.Replace("~", ResolveUrl("~"));

You can put all your style sheet links, javascript tags, etc inside the single literal. Because the literal doesn't render any additional HTML, there's no client-side cost to using it.

-Peter
compiledthoughts.com
 
Old October 6th, 2008, 12:46 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Thanks Peter, I think I'm close. But I'm getting this error.
"Compiler Error Message: CS0103: The name 'litDocHead' does not exist in the current context"

In MyPage.master, I wrapped my literal head markup as recommended.

<asp:literal id="litDocHead">
   ... HTML ...
</asp:literal>

Then in MyPage.master.cs, I included your ResolveUrl

    protected void Page_Load(object sender, EventArgs e)
    {
        litDocHead.Text = litDocHead.Text.Replace("~", ResolveUrl("~"));
    }

Thinking that possibly I was running this code at Load and the literal had not yet been created, I tried several other events Page_PreRender, PreRenderComplete, etc. but I received the same error each time. As you can probably tell I'm familiar with the various stages in page lifecycle, but not yet comfortable with exactly what's going on at each point. And this is my first time really using ResolveUrl.

Or is the problem that I'm trying to do this in the master page? I would really like to be able to call the stylesheet in the master page, and do so from the app root so that any page in any folder/subfolder will still locate the stylesheet and favicon.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old October 6th, 2008, 11:41 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The problem is most likely that you didn't define the literal in the codebehind. You need this somewhere in the class file:

protected Literal litDocHead;

-Peter
compiledthoughts.com
 
Old October 7th, 2008, 03:34 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I'd left runat="server" off the literal, so I added that, and now I can get the page to recognize litDocHead without defining it in the codebehind if I drop Page_Load for Page_Render. However it is still unstyled, and long term I want to develop this differently (which looks like it won't work with a literal). All my unchanging code in the <head>, I would like to put in a user control, and everything that changes I'd like to put in a content placeholder. Something like...

Code:
    <head>
        <echron:DocumentHead ID="compDocHead" AllowDuplicates="false" runat="server" />
        <asp:contentplaceholder id="cphTitleMetaExtraCss" runat="server" />
    </head>
This will pull in several elements that reference paths. I'll have one link tag for a favicon, one for style sheets (possibly more), and possibly a script tag that calls an external .js file (I'll definitely have one at the end of the page which is only working at the moment because it's not a root relative path.)

I get the feeling, this will be less an answer than a project. Any recommendations? Know any tutorials? I've mostly taught myself online, but I'm finding bloodly little about dealing with these paths in a master page/user control. Nor is my Professional ASP.NET 2.0 doing me much good. :(

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
server root and php_include paths mac os x jben.net Beginning PHP 8 November 14th, 2006 07:08 AM
Using document() with relative paths boen_robot XSLT 4 June 4th, 2006 05:41 PM
Virtual and relative paths - please explain SoC Classic ASP Basics 3 June 2nd, 2005 06:59 PM
Site root and document relative paths. nicnacs Dreamweaver (all versions) 5 October 5th, 2004 05:35 PM
HELP with relative paths in FileSystemObject stalker Javascript 5 September 4th, 2003 02:38 PM





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