user3624511 user3624511 - 5 months ago 34
Vb.net Question

Open multiple browser tabs from a single button click: ASP.NET

Hi I have following VB code is expecting open 2 tabs simultaneously when condition is true. But unfortunately it is opening first tab and second one is not opening. Please advice

If m_strIdNumber <> 0 AndAlso UserValNum <> 0 Then
' is working
Dim url As String = MainURL + "?qs=" + m_strIdNumber + "&usr=" + "local"
Dim script As String = String.Format("window.open('{0}');", url)
Page.ClientScript.RegisterStartupScript(Me.GetType(), "newPage" + UniqueID, script, True)

' But this is not working
Dim url1 As String = MainURL + "?qs=" + UserValNum + "&usr=" + "local"
Dim script As String = String.Format("window.open('{0}');", url1)
Page.ClientScript.RegisterStartupScript(Me.GetType(), "newPage" + UniqueID, script, True)
End If

Answer

From msdn "Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page."

So you need to give both calls of RegisterStartupScript a unique key. For example

Page.ClientScript.RegisterStartupScript(Me.GetType(), "newPage1" + UniqueID, script, True)
' ...
Page.ClientScript.RegisterStartupScript(Me.GetType(), "newPage2" + UniqueID, script, True)
Comments