asp.net - Master pages, paths, and a little ContentPlaceHolder -
i new asp.net. new asp period actually. forgive ignorance if obvious.
i used have code in master page changed in case text inside contenplaceholder replaced whatever page supplied.
<head runat="server"> <title><asp:contentplaceholder id="title" runat="server"></asp:contentplaceholder></title> <asp:contentplaceholder id="stylesheets" runat="server"> <link rel="stylesheet" type="text/css" href="s/main.css" /> </asp:contentplaceholder> <asp:contentplaceholder id="scripts" runat="server"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </asp:contentplaceholder> </head> it produced:
<head> <title></title> <link rel="stylesheet" type="text/css" href="s/main.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </head> now when changed decided going resolve href attributes.
<head runat="server"> <title><asp:contentplaceholder id="title" runat="server"></asp:contentplaceholder></title> <link rel="stylesheet" type="text/css" href="s/main.css" /> <asp:contentplaceholder id="stylesheets" runat="server"></asp:contentplaceholder> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <asp:contentplaceholder id="scripts" runat="server"></asp:contentplaceholder> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </head> and
<head runat="server"> <title><asp:contentplaceholder id="title" runat="server"></asp:contentplaceholder></title> <link rel="stylesheet" type="text/css" href="./s/main.css" /> <asp:contentplaceholder id="stylesheets" runat="server"></asp:contentplaceholder> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <asp:contentplaceholder id="scripts" runat="server"></asp:contentplaceholder> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </head> became
<head> <title></title> <link rel="stylesheet" type="text/css" href="masters/s/main.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </head> now, after reading on here , in book came not right.
<head runat="server"> <title><asp:contentplaceholder id="title" runat="server"></asp:contentplaceholder></title> <link rel="stylesheet" type="text/css" href="~/s/main.css" /> <asp:contentplaceholder id="stylesheets" runat="server"></asp:contentplaceholder> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <asp:contentplaceholder id="scripts" runat="server"></asp:contentplaceholder> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </head> produced:
<head> <title></title> <link rel="stylesheet" type="text/css" href="../s/main.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <!--[if lt ie 9]> <script type="text/javascript" src="js/html5.js"></script> <![endif]--> <script type="text/javascript" src="js/slideshow.js"></script> </head> the folder set-up so:
/masters/normal-page.master /index.aspx #uses normal-page.master now, question how can disable behavior or produce href="s/main.css" or equivalent? yes obvious solution move normal-page.master root, don't cluttering root folder.
also, if had used original , page gave place holder in page text between place holder tag replaced or appended? ( book seems assume know this. )
also, not using visual studio , not cannot justify cost yet. using notepad++.
there resolveurl method makes simple. try out , see if helps you:
<link href="<%= resolveurl("~/s/main.css")%>" rel="stylesheet" type="text/css" /> some additional reading: control.resolveurl method
Comments
Post a Comment