0

I am adding onclick attributes to the buttong and passing String mystring. mystring is the basically xml string. In xml string there is one tag which has value as " non-digit/letter in value 'COMM TEST' ". I am passing xml string as an agr to the javascript function DisplayFlightMessage here is the code

 msgButton.Attributes.Add("onclick", "DisplayFlightMessage('" & Utility.EncodeJsString(mystring) & "');return false")

The definition of DisplayFlightMessage is

<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);

}

and EncodeJsString defined as below

  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

As I am passing Single quote character in agr , it consider as comments and it will not open Model box. so I tired to replays " ' " with Char(32) but it will not work as expected . Any advice how I can handle single quote in this case .. Thanks in Advance ..

braX
  • 11,506
  • 5
  • 20
  • 33

0 Answers0