2

I want someone to inform me, how to implement JavaScriptStringEncode() function and what is used for ?

1
  • Please be a little more specific. Commented Nov 23, 2013 at 7:48

2 Answers 2

4

you can do like this

<script>
   // wrap in quotes automatically
   alert(<%=HttpUtility.JavaScriptStringEncode(MyStringHere, true)%>);
   // add quotes manually
   alert("<%=HttpUtility.JavaScriptStringEncode(MyStringHere)%>");
   alert("<%=HttpUtility.JavaScriptStringEncode(MyStringHere, false)%>");
</script>

HttpUtility.JavaScriptStringEncode() Method will convert html content to javascript compatible.

Sign up to request clarification or add additional context in comments.

Comments

0

"This method encodes strings. For instance, single quotation marks and double quotation marks are included as \' and \" in the encoded string.

URL encoding makes sure that all browsers correctly transmit text in URL strings. Characters such as a question mark (?), ampersand (&), slash (/), and spaces might be truncated or corrupted by some browsers. Therefore, these characters must be encoded in a elements or in query strings where the strings can be re-sent by a browser in a request string."

For more info enter link description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.