Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过ClientScript.RegisterStartupScript使用window.open仅打开两个新窗口_Javascript_.net_Vb.net - Fatal编程技术网

Javascript 通过ClientScript.RegisterStartupScript使用window.open仅打开两个新窗口

Javascript 通过ClientScript.RegisterStartupScript使用window.open仅打开两个新窗口,javascript,.net,vb.net,Javascript,.net,Vb.net,我的.NET(VB)应用程序中有一个点,提示用户选择要打印的零到多文档,这些文档在单独的新窗口中生成 所选文档列表从上一页传入,以管道分隔,作为querystring的一部分,然后拆分以创建文档列表。我的代码遍历这个列表,动态构建新窗口的URL,然后生成新窗口。出于某种原因,无论用户选择了三个还是更多,我最多只能得到两个新的弹出窗口,并且列表已完全正确填充 我知道每个窗口都需要一个唯一的键,这个键是动态构建的,看起来工作正常。代码如下。有人能发现我的错误吗 短暂性脑缺血发作 迈克 如果不是Req

我的.NET(VB)应用程序中有一个点,提示用户选择要打印的零到多文档,这些文档在单独的新窗口中生成

所选文档列表从上一页传入,以管道分隔,作为querystring的一部分,然后拆分以创建文档列表。我的代码遍历这个列表,动态构建新窗口的URL,然后生成新窗口。出于某种原因,无论用户选择了三个还是更多,我最多只能得到两个新的弹出窗口,并且列表已完全正确填充

我知道每个窗口都需要一个唯一的键,这个键是动态构建的,看起来工作正常。代码如下。有人能发现我的错误吗

短暂性脑缺血发作 迈克

如果不是Request.QueryString(“clttr”)=则无
暗弦
将脚本字符串设置为字符串
尺寸txnLttr为字符串
尺寸i为整数=0
像弦一样暗的strKey
lstLetters=Split(Request.QueryString(“clttr”),“|”)
对于每个txnLttr,以字母表示
strKey=“Letter”&i
如果UCase(Mid(txnLttr,Len(txnLttr)-2,3))=“PDF”,那么
strURL=“PDF_Prep.aspx?Case=“&Session(“SelKey”)和”&COLL=“&Session(“SelKey”)和”&UN=“&Session(“UserPKey”)和”&Letter=“&txnLttr
ScriptString=“”
ScriptString+=“window.open(“&strURL&”,“\u blank”);”
脚本字符串+=“”
RegisterStartupScript(Me.GetType、strKey、ScriptString)
其他的
'Response.Redirect('PrtSngleLttr.asp?Case=“&Session(“SelKey”)和“&Letter=“&txnLttr”)
'在此处编写代码,将变量txnLttr拆分为路径和字母名称…完成后,将适当的参数发送到MergeDocument。
如果txnLttr.包含(“/”),则
将文件名设置为字符串
将文件路径设置为字符串
Dim lastIndex As Integer=txnLttr.LastIndexOf(“/”)
fileName=Right(txnLttr,txnLttr.Length-(lastIndex+1))
filePath=Left(txnLttr,lastIndex)
strURL=“MergeDocument.aspx?Case=“&Session(“SelKey”)和”&LetterName=“&fileName&”&LetterPath=“&filePath&”&Mode=MERGE”
ScriptString=“”
ScriptString+=“window.open(“&strURL&”,“\u blank”);”
脚本字符串+=“”
RegisterStartupScript(Me.GetType、strKey、ScriptString)
其他的
strURL=“MergeDocument.aspx?Case=“&Session(“SelKey”)和&lettname=“&txnLttr&”&Mode=MERGE”
ScriptString=“”
ScriptString+=“window.open(“&strURL&”,“\u blank”);”
脚本字符串+=“”
RegisterStartupScript(Me.GetType、strKey、ScriptString)
如果结束
如果结束
i+=1
下一个
其他的
Response.Redirect(“casetail.aspx?case=“&Session(“SelKey”)和”&UN=“&Header1.UserNumber”)
如果结束
如果结束

我无法发现您的确切错误,但可能是您拉入URL的某个值包含一个嵌入的引号('),这会破坏javascript。将URL中的任何单引号替换为\'将解决此问题

如果将所有javascript都放在一个块中,那么跟踪问题就会容易得多

此外,现有代码会创建大量字符串,这在高使用率场景中会产生影响

为了解决这三个问题,我将重写您的代码,如下所示:

If Not Request.QueryString("clttr") = Nothing Then

    Dim ScriptString As New System.Text.StringBuilder(1000)
    lstLetters = Split(Request.QueryString("clttr"), "|")

    For Each txnLttr As String In lstLetters
        Dim strURL As New Sysem.Text.StringBuilder(500)

        If UCase(Mid(txnLttr, Len(txnLttr) - 2, 3)) = "PDF" Then
            strURL.Append("PDF_Prep.aspx?Case=").Append(Session("SelKey")).Append("&COLL=").Append(Session("SelKey")).Append("&UN=").Append(Session("UserPKey")).Append("&Letter=").Append(txnLttr)
        Else
           If txnLttr.Contains("/") Then
               Dim fileName As String
               Dim filePath As String
               Dim lastIndex As Integer = txnLttr.LastIndexOf("/")
               fileName = Right(txnLttr, txnLttr.Length - (lastIndex + 1))
               filePath = Left(txnLttr, lastIndex)

               strURL.Append("MergeDocument.aspx?Case=").Append(Session("SelKey")).Append("&LetterName=").Append(fileName).Append("&LetterPath=").Append(filePath).Append("&Mode=MERGE")
           Else
               strURL.Append("MergeDocument.aspx?Case=").Append(Session("SelKey")).Append("&LetterName=").Append(txnLttr).Append("&Mode=MERGE")
            End If
        End If

        ScriptString.Append("window.open('").Append(strURL.ToString().Replace("'", "\'")).Append("', '_blank');").AppendLine()
    Next

    ClientScript.RegisterStartupScript(Me.GetType, "Letters", ScriptString.ToString(), True)
Else
    Response.Redirect("CaseDetail.aspx?case=" & Session("SelKey") & "&UN=" & Header1.UserNumber)
End If

这只是一些值得思考的东西——如果您首先开发一个只支持javascript的原型,然后尝试使其与您的服务器代码一起工作,可能会有所帮助。它将使您的js与服务器分离,并可能更好地帮助您找出问题发生的位置。谢谢,伙计,这非常有效!我喜欢你的方法——比我的方法优雅得多。我喜欢你只写了一次整个剧本。再次感谢!
If Not Request.QueryString("clttr") = Nothing Then

    Dim ScriptString As New System.Text.StringBuilder(1000)
    lstLetters = Split(Request.QueryString("clttr"), "|")

    For Each txnLttr As String In lstLetters
        Dim strURL As New Sysem.Text.StringBuilder(500)

        If UCase(Mid(txnLttr, Len(txnLttr) - 2, 3)) = "PDF" Then
            strURL.Append("PDF_Prep.aspx?Case=").Append(Session("SelKey")).Append("&COLL=").Append(Session("SelKey")).Append("&UN=").Append(Session("UserPKey")).Append("&Letter=").Append(txnLttr)
        Else
           If txnLttr.Contains("/") Then
               Dim fileName As String
               Dim filePath As String
               Dim lastIndex As Integer = txnLttr.LastIndexOf("/")
               fileName = Right(txnLttr, txnLttr.Length - (lastIndex + 1))
               filePath = Left(txnLttr, lastIndex)

               strURL.Append("MergeDocument.aspx?Case=").Append(Session("SelKey")).Append("&LetterName=").Append(fileName).Append("&LetterPath=").Append(filePath).Append("&Mode=MERGE")
           Else
               strURL.Append("MergeDocument.aspx?Case=").Append(Session("SelKey")).Append("&LetterName=").Append(txnLttr).Append("&Mode=MERGE")
            End If
        End If

        ScriptString.Append("window.open('").Append(strURL.ToString().Replace("'", "\'")).Append("', '_blank');").AppendLine()
    Next

    ClientScript.RegisterStartupScript(Me.GetType, "Letters", ScriptString.ToString(), True)
Else
    Response.Redirect("CaseDetail.aspx?case=" & Session("SelKey") & "&UN=" & Header1.UserNumber)
End If