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!!
Printable View
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!!
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.
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!!
I found a much easier way to do this...
http://asp.net/Forums/ShowPost.aspx?...1&PostID=33382Code:response.write("<script language=javascript>window.open(URL, TARGET='another');</script>")
Thanks for the help!!!