Re: Passing a string to a client side function

Discussion in 'ASP .Net' started by Matt Howeson, Jan 29, 2004.

  1. Matt Howeson

    Matt Howeson Guest

    I can suggest 2 similar options :

    1. Put the xml string in a textbox control (and set the display style to
    none using css stylesheet) then simply reference the value of your textbox
    control, to get the XML string.

    2. (Probably the better one) Add a hidden input field to your form, set the
    runat attribute to server and then simply assign your XML string as the
    value of the hidden input field from within your code behind. Using this
    method the encoding is taken care of for you as the whole lot will be html
    encoded. (I pretty sure this should then work fine, but I may be wrong!!)

    Hope one of the above works for you.


    "Jorell" <> wrote in message
    > 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
    Matt Howeson, Jan 29, 2004
    1. Advertisements

  2. Matt Howeson

    Matt Howeson Guest


    If you use the option of outputting your text to a form variable you should
    not need to use escape characters at all. If you just leave the string
    exactly as you want it to appear and output it to the form variables, when
    you retrieve the value you should see exactly what you are looking for. Or
    is there something that I am missing as to why do you need to put escape
    characters in?


    "Jorell" <> wrote in message
    > Hi there. Thank you for the suggestion. I tried this as I figured the same

    however the value, innerText and innerHtml etc properties all return the
    HTML but with the escape characters ie. \"
    > This still causes and issue and without actually doing a loop to look for

    escape characters and replacing them...but there is a possibly of not
    catching all of them.
    > Essentially I am just writing this HTML to a div using the document.write

    method and then printing the div using execWB.
    > Any ideas would be great thank you!
    > Jorell
    Matt Howeson, Jan 30, 2004
    1. Advertisements

  3. Hi there Matt
    I actually don't want the characters in the string. What I have is Complex HTML that I have created in a server function

    I have a js function which needs to take that HTML and write it to the Body of an IFrame that it creates. ( that can't be changed) So basically what I need to be able to do is end up with a variable inside that js function which is straight HTML no escapes.

    Mostly the problem is if you use textboxes of any sort...the innerHtml, innerText, Text, or value fields always return the value with escape charaters when accessing them from the client. I am not sure why

    So no matter what I put the HTML in, it adds escape chars

    Any ideas? I appologize if it is unclear! Thank yo

    =?Utf-8?B?Sm9yZWxs?=, Jan 30, 2004
    1. Advertisements

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
  2. Kevin Spencer
    Jan 29, 2004
  3. Mike Fellows
    Eliyahu Goldin
    Jun 29, 2004
  4. Replies:
    Eliyahu Goldin
    Jul 13, 2006
  5. Boss302
    Nov 21, 2006

Share This Page