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”>
    <title></title>
    <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>
</head>

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

protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        Page.Header.DataBind();
    }

 

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