Click here to Skip to main content
13,350,861 members (55,226 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 9 Sep 2011

SharePoint 2010 Custom Master Page Tips and Tricks -> JavaScript and StyleSheet Reference

, 16 Nov 2013
Rate this:
Please Sign up or sign in to vote.
SharePoint 2010 Custom Master Page Tips and Tricks -> JavaScript and StyleSheet reference.

Quite recently, we went to a client to implement a set of custom MasterPages along with its own set of the JavaScript framework and styling-sheets.

Everything went pretty smooth for development and UAT environment until the final deployment to the production farm. After firing off the PS script, everything seems pretty dandy and up-running, except the styling and Ajax stopped working for unknown reasons.

Once quickly fire-off my best pal (Firebug and Chrome Development Console), the problem was revealed in a second by the Absolutely Path not working since we altered the site-collection structure in the production environment.

Then the question came to me that how we could come up a better reference URL rather than hard-coded or the absolute one. After quickly looking this up from MSDN, I came up this quick and neat solution below:

JavaScript Files

<asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" 

EnablePartialRendering="true" EnableScriptGlobalization="false" 


Path="<%$SPUrl:~SiteCollection/Style Library/ProjectPortal/js/jquery-1.5.2.js%>">


StyleSheet Files

<SharePoint:CssRegistration ID="CssRegistration1"

name="<% $SPUrl:~sitecollection/Style Library/ProjectPortal/ppb-styles.css  %>" 

After="corev4.css" runat="server"/>

As the codes shown above, the magic trick here is all about leveraging syntax in order to get the proper URL path populated regardless of the change of the URL path since the site collection level structure has been modified.

As for the sake of the best practice, we have determined to use WSP to deploy all custom MasterPages, styling recourse and Ajax script components, thereby this little tip is definitely benefitting us in the long-run.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 16 Nov 2013
Article Copyright 2011 by Eric Xue (brokensnow)
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid