I am writing a small script to be ran in a dialog when it opens. In the code I have a string type variable with html code, such as string script = <a onclick=runthis('This will not work with white spaces')><a/>. That will not work but if i take out all the white spaces it will work fine. Question is is there a way to pass in a parameter with spaces or any other way to do this? thanks for any examples or suggestions.
Small example of the error, This is a string in c#.
"<div id="DialogEditPhoto" style="display: inline-block; position: relative; cursor: pointer" " +
"onclick=EditPhoto("Wlcometo thesouth",'dsaasd','" + pic.ID + "');>"
Some of the character encoding you’re doing is a little unnecessary. You need quotes around your JS function, which is why the whitespace is causing it not to work.
And before you sent it to the client, let .NET do the character encoding for you:
Also, you didn’t close your opening
<div>tag; I’m not sure if you were intending to, but I added it anyway.