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

Discussion in 'ASP .Net' started by Chris, Mar 24, 2006.

  1. Chris

    Chris Guest

    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..
     
    Chris, Mar 24, 2006
    #1
    1. Advertisements

  2. Chris

    Oisin Guest

    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
     
    Oisin, Mar 24, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.