0

Here how we are getting user company name from session in aspx page

 var Details = "AgentCompanyName=" + encodeURIComponent("<%=((Agent_Html5.AgentClassLib.clsAgentSession)Session["UserSession"]).strAgentCompanyName%>");

above code works fine if strAgentCompanyName doesn't contain quote(single,double) but that in it then it not works. eg. if Agent company name name provided as : David "Mike" Bela solution then it raise error as it is not appropriate string near Mike keyword.

Details = "AgentLastName= David "Mike" Bela solution"

How to handle for single/double quote?

Kaishu
  • 377
  • 1
  • 7
  • 21

1 Answers1

0

You need to escape double quotes before output for javascript. So that it will be valid syntax. You should use something like:

<%= yourValue.Replace("\"", "\\\"") %>

Also you can use a better way of escaping with javascript:

var Details = "AgentCompanyName=" + $("<div/>").text("<%=yourValue%>").html(); 

With this you will create in memory DIV element, set value as text and get as escaped HTML.