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. Advertising

  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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SStory
    Replies:
    5
    Views:
    5,758
    SStory
    Jun 7, 2004
  2. Roger Helliwell

    Single and Double Quotes in ASP.NET

    Roger Helliwell, Jul 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    10,179
    Roger Helliwell
    Jul 6, 2004
  3. Replies:
    10
    Views:
    1,278
    Anno Siegel
    Apr 17, 2006
  4. Replies:
    4
    Views:
    168
    Ted Zlatanov
    Sep 13, 2006
  5. Replies:
    2
    Views:
    128
    slebetman
    Jul 7, 2008
Loading...

Share This Page