将会话变量添加到脚本字符串?

时间:2013-07-11 17:18:52

标签: asp.net vb.net

我使用下面的代码生成一个弹出框。在哪里说“信息准备提交”我想添加“你的参考号是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

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分: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