我将onclick属性添加到buttong并传递String mystring。 mystring基本上是xml字符串。在xml字符串中有一个标签,其值为"非数字/字母值' COMM TEST' &#34 ;.我将xml字符串作为agr传递给javascript函数DisplayFlightMessage
这里是代码
msgButton.Attributes.Add("onclick", "DisplayFlightMessage('" & Utility.EncodeJsString(mystring) & "');return false")
DisplayFlightMessage
的定义是
<script id="DetailCode" type="text/javascript">
function DisplayFlightMessage(msg) {
var arguments = new ModalDialogArgsCollection();
arguments.addCollectionItem(msg);
var url = "../ModalDialogs/FlightStatusMessage.aspx"
var dialogWidth = 500;
var dialogWindowHeight = 300;
var dialogBodyHeight = dialogWindowHeight - 35;
var opt = "dialogWidth:" + dialogWidth + "px;dialogHeight:" + dialogWindowHeight + "px;center:yes;status:no;scroll:no";
arguments.style = "width:" + dialogWidth + "px;height:" + dialogBodyHeight + "px;"
var modalDialogStatus = window.showModalDialog(url, arguments, opt);
}
和EncodeJsString
定义如下
Public Function EncodeJsString(ByVal s As String) As String
Dim sb As New StringBuilder()
' sb.Append("""")
For Each c As Char In s
Select Case c
Case """"c
sb.Append("\""")
Exit Select
Case "\"c
sb.Append("\\")
Exit Select
Case ControlChars.Back
sb.Append("\b")
Exit Select
Case ControlChars.FormFeed
sb.Append("\f")
Exit Select
Case ControlChars.Lf
sb.Append("\n")
Exit Select
Case ControlChars.Cr
sb.Append("\r")
Exit Select
Case ControlChars.Tab
sb.Append("\t")
Exit Select
Case Else
Dim i As Integer = AscW(c)
If i < 32 OrElse i > 127 Then
sb.AppendFormat("\u{0:X04}", i)
Else
sb.Append(c)
End If
Exit Select
End Select
Next
' sb.Append("""")
Return sb.ToString()
End Function
当我在agr中传递单引号字符时,它会将其视为注释,并且不会打开模型框。所以我厌倦了重播&#34; &#39; &#34;使用Char(32)但它不会按预期工作。 在这种情况下如何处理单引号的任何建议.. 在此先感谢..