1

I have a tilde path. I would like to convert it into client url

    var path = "~/Presentation/Resources/Images/masterPage/cleanup.png";
    var a =  '<%=Page.ResolveClientUrl(" '+path+' ") %>';

    var b = '<%=ResolveUrl("~/Presentation/Resources/Images/masterPage/cleanup.png") %>';

alert("var a-->"+a);
alert("var b-->"+b);

although the code above seems the same, the results I obtain for var a and var b are very different.

Result

var a --> ~/Presentation/Resources/Images/masterPage/cleanup.png
var b --> ../../Resources/Images/masterPage/cleanup.png

I have a variable that stores the path, but I failed to get the result exactly like var b. What can I do for var a so that I can get the result like var b?

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
DEN
  • 1,893
  • 7
  • 27
  • 51

1 Answers1

1

The methods you are calling, ResolveClientUrl and ResolveUrl, are different. ResolveClientUrl tells you the URL relative to the page you are on; ResolveUrl tells you the URL relative to the site root. You can find a more thorough description at http://www.andornot.com/blog/post/ResolveUrl-vs-ResolveClientUrl.aspx

There is also more info in this other SO question.

Community
  • 1
  • 1
Jeff Siver
  • 7,434
  • 30
  • 32
  • well,i tried with ResolveUrl and ResolveClientUrl. both of this also not returning me the "../../" relative path :( – DEN Sep 14 '11 at 04:50