From dePoPo.net

How to send a response.redirect to another window

Posted in: ASP.NET
By dePoPo
Sep 20, 2009 - 3:49:58 PM

Response.redirect is executed on the server and sends a special HTTP response back to the client. Since a new window or tab must be openend on the client side, you can not archieve this with response.redirect.
So, we need a little helper script to make this happen:


<script type="text/javascript">
    window.open("destinationpage.aspx");
</script>



Including scripts in your code parts may cause readability to suffer, so to change this in an easy to re-use function, create a new module and place the following code in it:


    Public Sub RedirectWindow(ByVal s_destinationURL As String)

        Dim mysession As HttpContext = HttpContext.Current
        mysession.Response.Write("<script type=" & Chr(34) & "text/javascript" & Chr(34) & ">")
        mysession.Response.Write("window.open(" & Chr(34) & s_destinationURL & Chr(34) & ");")
        mysession.Response.Write("</script>")

    End Sub



Now, you can use the following in your asp.net code

' --- Normal redirect
Response.Redirect("Newlocation.aspx")

' --- Redirect to a new window
RedirectWindow("Newlocation.aspx")

© Copyright 2010 by dePoPo.net