Deeptechtons
Deeptechtons

Reputation: 11125

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/

Upvotes: 0

Views: 1660

Answers (3)

Etch
Etch

Reputation: 3054

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") %>');

Upvotes: 1

Hanlet Esca&#241;o
Hanlet Esca&#241;o

Reputation: 17380

try this out:

Code Behind:

 protected void Page_Load(object sender, EventArgs e)
        {
                string script;
                script = "function getURL(which){ if(which=='1') { return '" + ResolveUrl("~/Default.aspx") + "'; } }";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "MyFunction", script, true);
        }

JAVASCRIPT-With JQuery:

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        alert(getURL('1'));
    });

</script>

you will have to know which URL to load, but it works like a charm. Good luck!

Upvotes: 0

idm
idm

Reputation: 1748

It seems like $script.path("~/js"); would be better. Also, please, write down the wrong path here, i'll try to guess why it is wrong

Upvotes: 0

Related Questions