How to add script reference in Master Page to make accessible from all the directory

To add script file reference in master page to make it accessible from all the pages from all the directory of the website , add the script reference in the following way :

Suppose the web structure is as follows :

Structure of the WebSite

add following lines to masterpage.master

<head runat=”server”>
    <script type=”text/javascript” src='<%#ResolveUrl(“~/JQuery/jquery-ui-1.8.17.custom/js/jquery-1.7.1.min.js” ) %>’ ></script>
    <script type=”text/javascript” src='<%#ResolveUrl(“~/JQuery/jquery-ui-1.8.17.custom/js/jquery-ui-1.8.17.custom.min.js” ) %>’ ></script>

And then add Page.Header.DataBind();  in the OnLoad method of the MasterPage.master.cs file :

protected override void OnLoad(EventArgs e)


Thats it, now functionality from the script files are available to all the files in the website that uses the master page.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: