Search code examples
c#javascriptasp.netmaster-pagesdynamic-script-loading

asp.net script loader master pages and path errors


I am using [script.js][1] as async script loader along with my master page. The pages on the root are working fine using the master page file as it's master page. When it comes to web pages that are inside folders like below then the path does not work fine. Script loader loads the files from wrong url. How do i make it load from correct url regardless of the path.

Admin

-users

 -createuser.aspx

The contents of the loader file

//show the path to load scripts files from
$script.path("/js/");

//load jquery first and then load the dependent scripts
$script.order(["jquery.min","slider"],function(){
    //load the application specific file
    $script("app");
});

how do i get the path to web application on client side for example path should resolve to http://domainname/virtualdirectory/js/


Solution

  • Are you looking for somthing like this?

    <%= Page.ResolveClientUrl("~/Scripts/test.min.js") %>
    

    This will resolve the url for you from the HTML side. I am not familiar with $script.path, but I am wondering if you can do somthing like $script.path('<%=Page.ResolveClientUrl("~/Scripts/test.min.js") %>');