Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. apostrophes or quotes creating problem while passing to javascript

apostrophes or quotes creating problem while passing to javascript

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dhruvil
    wrote on last edited by
    #1

    Hi all, I am passing values from my datagrid to client side javascript function. In that some of the values contains apostrophes or quotes, which is creating error.I guess, this is because of values passed to browser are in ' ' quotes, and it encounter an apostrophes or quotes, that creates an error. Anybody have some solution of this problem? Please let me know. Thank you very much, NIKI

    E G 2 Replies Last reply
    0
    • D Dhruvil

      Hi all, I am passing values from my datagrid to client side javascript function. In that some of the values contains apostrophes or quotes, which is creating error.I guess, this is because of values passed to browser are in ' ' quotes, and it encounter an apostrophes or quotes, that creates an error. Anybody have some solution of this problem? Please let me know. Thank you very much, NIKI

      E Offline
      E Offline
      eggsovereasy
      wrote on last edited by
      #2

      Try running the values through System.Web.HttpUtility.HtmlEncode()

      G H 2 Replies Last reply
      0
      • D Dhruvil

        Hi all, I am passing values from my datagrid to client side javascript function. In that some of the values contains apostrophes or quotes, which is creating error.I guess, this is because of values passed to browser are in ' ' quotes, and it encounter an apostrophes or quotes, that creates an error. Anybody have some solution of this problem? Please let me know. Thank you very much, NIKI

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Encode the string correctly to be a string value in Javascript: theString = theString.Replace("\\", "\\\\").Replace("'", "\\'"); --- b { font-weight: normal; }

        D 1 Reply Last reply
        0
        • E eggsovereasy

          Try running the values through System.Web.HttpUtility.HtmlEncode()

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          That doesn't affect the apostrophes at all. Apostrophes has no special meaning in HTML, so they are not changed by the HtmlEncode method. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • E eggsovereasy

            Try running the values through System.Web.HttpUtility.HtmlEncode()

            H Offline
            H Offline
            Hy Chanhan
            wrote on last edited by
            #5

            I have the same problem too. I am a student at BBU in Cambodia. In major: Information Technology. This web is so interested.

            1 Reply Last reply
            0
            • G Guffa

              Encode the string correctly to be a string value in Javascript: theString = theString.Replace("\\", "\\\\").Replace("'", "\\'"); --- b { font-weight: normal; }

              D Offline
              D Offline
              Dhruvil
              wrote on last edited by
              #6

              Hi Guffa, I have a line in javascript function like this: function myfunction(value1) { document.GetElementById('td').innertext=value1; } how can i parse the value1 field which contain apostrophes, such a way that it will not create problem while passing to the javascript function from server datagrid. and also, i dont want to eliminate apostrophes from the output on client side. Thanks, NIKI

              G 1 Reply Last reply
              0
              • D Dhruvil

                Hi Guffa, I have a line in javascript function like this: function myfunction(value1) { document.GetElementById('td').innertext=value1; } how can i parse the value1 field which contain apostrophes, such a way that it will not create problem while passing to the javascript function from server datagrid. and also, i dont want to eliminate apostrophes from the output on client side. Thanks, NIKI

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                You do as I showed when creating the code that calls that function. --- b { font-weight: normal; }

                D 1 Reply Last reply
                0
                • G Guffa

                  You do as I showed when creating the code that calls that function. --- b { font-weight: normal; }

                  D Offline
                  D Offline
                  Dhruvil
                  wrote on last edited by
                  #8

                  Thank you very much Guffa, The logic is perfectly working with my code. Thank you very much. I really appreciate your help. NIKI

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups