Results 1 to 4 of 4

Thread: Opening another browser

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342

    Opening another browser

    How do I open another browser window when a user clicks on a button?

    I don't seem to have the Window object (I don't want to use JavaScript if at all possible)

    Thanks!!

  2. #2
    Member
    Join Date
    Sep 2001
    Location
    Fishburn
    Posts
    45
    Since there's no physical connection between client and server I imagine even if there is a neat way of doing it, behind the scenes some client-side scripting would be used. Just like when using autopostback with a listbox.

    The way I do this is have in the ASPX file...

    <script language="vbscript">
    Sub BrowseNewWindow(URL)
    window.open URL, "NewWindow"
    End Sub
    </script>


    And then on the code-behind for server-side, create the sub routine...

    Private Sub OpenNewWindow(ByVal URL As String)
    RegisterStartupScript("BrowseScript", "<script language=""VBSCRIPT"">BrowseNewWindow(""" & URL & """)</script>")
    End Sub

    And then on any click event, you can use...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    OpenNewWindow("http://www.google.co.uk")
    End Sub

    This automatically adds the script block which will execute as soon as the page is loaded in the browser. Although its still using scripting, I think its neater than having a load of script added to the ASPX page.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    I have added the script to my .ASPX page and the code behind method, but when I click the button nothig happens. I steped through the execution and it is firing the RegisterStartupScript it's just not doing anything on the client end.


    Thanks!!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    I found a much easier way to do this...

    Code:
    response.write("<script language=javascript>window.open(URL, TARGET='another');</script>")
    http://asp.net/Forums/ShowPost.aspx?...1&PostID=33382

    Thanks for the help!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width