1

我正在使用下面的代码来生成一个弹出框。在哪里说“信息已准备好提交”我想添加“您的参考号是 12345”我正在使用会话获取该参考号,即会话(“ID”)。有没有办法可以将它添加到字符串中?

    Try
        Dim msg As String = "Hello!"
        Dim script As String = "if(confirm('The information is ready to be submitted')) {window.location.href ='frmMain.aspx'; }"
        ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "Test", script, True)
    Catch ex As Exception
    End Try
4

2 回答 2

1

尝试这个:

Try
    Dim msg As String = "Hello!"
    Dim idValue As String = CType(Session("ID"), String)
    Dim script As String = "if(confirm('The information is ready to be submitted. Your reference number is " & idValue & "')) {window.location.href ='frmMain.aspx'; }"
    ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "Test", script, True)
Catch ex As Exception
End Try
于 2013-07-11T17:31:03.580 回答
1

是的。只需将信息添加到您的脚本字符串(我将字符串切换到 stringbuilder 以提高效率):

Dim sbScript As New System.Text.StringBuilder(200)

sbScript.Append("if(confirm('The information is ready to be submitted. Your reference number is ").Append(Session("ID"))
sbScript.Append("')) {window.location.href ='frmMain.aspx'; }")
ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "Test", sbScript.ToString(), True)
于 2013-07-11T17:30:11.447 回答