I have some vb code as below:
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
sb.Append("<script type=""text/javascript"">")
sb.Append(" function addRow() {")
sb.Append(" var div = document.createElement('div');")
sb.Append(" div.className = 'panel panel-info';")
sb.Append(" div.innerHTML = '")
For i = 0 To dtf.Rows.Count - 1
Dim NAME As String = dtf.Rows(i)(0).ToString
Dim Datee As String = dtf.Rows(i)(3).ToString
Dim commentsth As String = dtf.Rows(i)(2).ToString
Dim urlh As String = dtf.Rows(i)(1).ToString
sb.Append("<div class=""panel-heading"">")
sb.Append(" <h4 class=""panel-title"">")
sb.Append(" <a data-toggle=""collapse"" data-parent=""#accordion"" href=""" & urlh & """>")
sb.Append(" " & NAME & " " & Datee & "</a>")
sb.Append(" </h4>")
sb.Append(" </div>")
sb.Append(" <div id=""collapse" & i & """ class=""panel-collapse collapse in"">")
sb.Append(" <div class=""panel-body"">")
sb.Append(" " & commentsth & "")
sb.Append(" </div>")
sb.Append(" </div>")
Next
sb.Append("';")
sb.Append(" document.getElementById('WorldNews').appendChild(div);}")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "MyScript", sb.ToString())
This code is to append a java-script code to the web page.
My Problem is if, for instance the variable
commentsth
contains character
' or " or \
it will affect the output, because ' or " could be a closing marks for a string
ie: if commentsth="he's.." then problem happen..
" '<div class=""panel-body"">" & he's.. & ""
How can I avoid this situation.