4

I have the following function which I pass in a value, but this value is coming from the database. However I get the following javascript when doing the following:

showrootcausedetails('showrootcause',true,'<%# eval("Root Cause Analysis").ToString() %>')

I know I have to escape the characters, but How can I do that without knowing what is in the actual string?

Thanks,

Jacob

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
Jacob
  • 41
  • 2

1 Answers1

7

Call Server.JavaScriptStringEncode.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    +1 - OP might be on less than .NET 4.0 though. There's some solutions to that here - http://stackoverflow.com/questions/2920752/is-there-a-standard-way-to-encode-a-net-string-into-javascript-string-for-use-in – Russ Cam Mar 27 '11 at 22:12
  • Do I need to reference something before using that function ? – Jacob Mar 27 '11 at 22:15
  • I am getting the the same error text for this: `var setScript = "";` – SearchForKnowledge Feb 10 '15 at 20:12