c# - Escaping single quotes in Response.Write -


i'm not asp.net developer happen work on javascript side of code-base has simple asp.net in there well. need escape dynamic text before sets javascript object property:

text: '<% =_servicemessagetext %>' 

i tried use httputility.javascriptstringencode didn't work , didn't should expect it. wondering if there simple ways escape single quotes, possibly avoiding regex.

nb: actual text encoded, single quotes stored &#39;, when retrieved represented actual single quote character, causing javascript parse error.

update

perhaps should change javascript side to:

text: "<% =_servicemessagetext %>" 

and use server.htmlencode escape double quotes?

yes, correct; use double quote "" escape/delimit server side string , single quotes should used delimiting client side strings. should rather

"<% =_servicemessagetext %>" 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -