I am generating a javascript alert box from codebehind in asp.net(vb).
The code:
Catch ex As Exception
MesgBox(\"Error in up
Add Imports System.Web.Script.Serialization
to the top of your file, then try this:
Private Sub MesgBox(ByVal sMessage As String)
Dim serializer as New JavaScriptSerializer()
Dim msgedtble As String = serializer.Serialize(sMessage)
Page.ClientScript.RegisterStartupScript(Me.GetType, "myScripts",
"")
End Sub
Using JavaScriptSerializer should take care of the linebreaks, single quotes, and everything else we haven't already thought of.