Asp.NET Javascript string, want to pass '(single quotes' within '(single quotes)

C

Chris

Hi,
This is a very basic problem, but i am not able to solve it.

msgStr = "<script language =javascript>alert('An exception abc
occured')</script>"
Page.RegisterStartupScript("exception", msgStr)

But if I have want a string like the one shown below, how can I achieve
this ? (Note the single quotes in 'abc')

msgStr = "<script language =javascript>alert('An exception 'abc'
occured')</script>"

Basically, I have a module which creates a string like the msgStr. And
I am passing a string. In this case, I will be passing "An exception
'abc' occured".

But finally, the string becomes as shown in the above line, and gives
some javascript error saying ')' expected.
I tried using 2 single quotes too, but its not working.

TIA..
 
O

Oisin

heh, don't you love these problems:

string test = "alert('this is a message \\'test\\' from my script')";

you need to escape the escape character ;)

- Oisin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top