Re: Passing a string to a client side function

Discussion in 'ASP .Net' started by Kevin Spencer, Jan 29, 2004.

  1. Just replace any single and double quotes with "\char" where "char" is the
    character (e.g. \' or \"). The backslash is the escape character in
    JavaScript.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Jorell" <> wrote in message
    news:...
    > Hi everyone,
    > I have an XML that I create on the fly. I need to pass this to a

    Javascript function and I do it in this way:
    >
    > Page.RegisterStartupScript("Test", "<script

    language=""javascript"">printHidden('" & XML & "')</script>")
    >
    > This works however if you encase the XML in single quotes then there could

    possibly a terminating ' in the XML and on the other hand if you encase the
    XML in double quotes and there is a single " in the XML...this becomes the
    terminator and the client side throws an error: Unterminated string constant
    > The user enters the information the XML is built with and we must allow

    them the ability to enter these any characters.
    >
    > What I need to do is encode the string server side before it is passed and

    then unencode it on the client.
    >
    > I have attempted to use Regex.Escape on the Server then unescape() on the

    client with no luck.
    >
    > Any ideas/suggestions would be great! Thank you
    >
    > Jorell
     
    Kevin Spencer, Jan 29, 2004
    #1
    1. Advertising

  2. I agree however I was kind of looking at that as a last resort. If possible I was hoping there was functions on both sides that I had missed that would take care of this for me. Any chance this is possible? Thank you again

    Jorell
     
    =?Utf-8?B?Sm9yZWxs?=, Jan 29, 2004
    #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. ken busse
    Replies:
    2
    Views:
    472
  2. Matt Howeson
    Replies:
    2
    Views:
    468
    =?Utf-8?B?Sm9yZWxs?=
    Jan 30, 2004
  3. Mike Fellows
    Replies:
    8
    Views:
    450
    Eliyahu Goldin
    Jun 29, 2004
  4. Replies:
    4
    Views:
    7,318
    Eliyahu Goldin
    Jul 13, 2006
  5. Boss302
    Replies:
    0
    Views:
    1,084
    Boss302
    Nov 21, 2006
Loading...

Share This Page