views:

87

answers:

3

Hi

Im using my asp.net code behind to register some startup script.

The following code gets rendered to the browser.

var rotator = new ImageRotator('rotateImg');
rotator.AddImage('DisplayThumbnailImage.aspx?FilePath=C:\Development\Projects\TouchSA\Trunk\WebSite\Gallery\photo_4.PNG&ThumbnailWidth=535&ThumbnailHeight=316');
rotator.Rotate();

This looks right...but when the AddImage method receives the parameter, all the backslashes are gone. Why?

A: 

I suspect you simply need to escape the backslashes. i.e. Use \\ instead of \ in your string.

var rotator = new ImageRotator('rotateImg');
rotator.AddImage('DisplayThumbnailImage.aspx?FilePath=C:\\Development\\Projects\\TouchSA\\Trunk\\WebSite\\Gallery\\photo_4.PNG&ThumbnailWidth=535&ThumbnailHeight=316');
rotator.Rotate();
Noldorin
+4  A: 

Answering your question without giving any remarks to the local url. ;)

To get an "\" you have to escape it... Like this

'DisplayThumbnailImage.aspx?FilePath=C:\\Development\\Projects\\TouchSA\\Trunk\\WebSite\\Gallery\\photo_4.PNG&ThumbnailWidth=535&ThumbnailHeight=316'
ullmark
How do I double escape the URL. When rendering the javascript from c# code, Its escaped like youve shown above. So do I need to escape the result aswell?
Morph
+2  A: 

Encode your URL and you'll have no problems.

Server.UrlEncode()

To decode

Server.UrlDecode()

Vince