esamAhmed esamAhmed - 1 year ago 151
ASP.NET (C#) Question

How to correctly use the JavaScriptStringEncode() method?

I want someone to inform me, how to implement

function and what is used for ?

Answer Source

you can do like this

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

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