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 ', 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
Post a Comment