I have a point in my .NET (VB) application at which the user is prompted to select zero to many documents to be printed, which are spawned off in separate new windows.
The list of documents selected is passed in from the previous page, pipe-delimited, as part of the querystring, which is then split to create a list of documents. My code iterates through this list, builds the new window’s URL dynamically and then spawns the new window. For some reason I’m getting a maximum of two new pop-up windows, regardless of whether the user chose three or more, and the list is being populated fully and properly.
I know that I need a unique key for each window, and that is being built dynamically and appears to be working fine. Code is below. Can anyone spot my error?
TIA
Mike
If Not Request.QueryString("clttr") = Nothing Then
Dim strURL As String
Dim ScriptString As String
Dim txnLttr As String
Dim i As Integer = 0
Dim strKey As String
lstLetters = Split(Request.QueryString("clttr"), "|")
For Each txnLttr In lstLetters
strKey = "Letter" & i
If UCase(Mid(txnLttr, Len(txnLttr) - 2, 3)) = "PDF" Then
strURL = "PDF_Prep.aspx?Case=" & Session("SelKey") & "&COLL=" & Session("SelKey") & "&UN=" & Session("UserPKey") & "&Letter=" & txnLttr
ScriptString = "<script language='javascript'>"
ScriptString += "window.open('" & strURL & "', '_blank');"
ScriptString += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, strKey, ScriptString)
Else
'Response.Redirect("PrtSngleLttr.asp?Case=" & Session("SelKey") & "&Letter=" & txnLttr)
'Write code here to split the variable txnLttr into path and Letter name...Once done send appropriate params to MergeDocument.
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 = "MergeDocument.aspx?Case=" & Session("SelKey") & "&LetterName=" & fileName & "&LetterPath=" & filePath & "&Mode=MERGE"
ScriptString = "<script language='javascript'>"
ScriptString += "window.open('" & strURL & "', '_blank');"
ScriptString += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, strKey, ScriptString)
Else
strURL = "MergeDocument.aspx?Case=" & Session("SelKey") & "&LetterName=" & txnLttr & "&Mode=MERGE"
ScriptString = "<script language='javascript'>"
ScriptString += "window.open('" & strURL & "', '_blank');"
ScriptString += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, strKey, ScriptString)
End If
End If
i += 1
Next
Else
Response.Redirect("CaseDetail.aspx?case=" & Session("SelKey") & "&UN=" & Header1.UserNumber)
End If
End If
I can’t spot your exact error, but it could be that one of the values you are pulling into the URL contains an embedded quote (‘), which would destroy the javascript. Replacing any single quotes with \’ in the URL will resolve this issue.
You are going to have a much easier time tracking the issue down if you have all of the javascript in a single block.
In addition, your existing code creates a lot of strings, which will have an impact in a high usage scenario.
To resolve all three of these issues, I would rewrite your code as follows: