简体   繁体   中英

Use Asp.net to inject javascript

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?

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'

Encode your URL and you'll have no problems.

Server.UrlEncode()

To decode

Server.UrlDecode()

I suspect you simply need to escape the backslashes. ie 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM