View Full Version : Pop Up In New Window

03-08-2007, 10:34 PM
Ive got the following as the code behind a button in asp.net:

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
End Sub

what code should go after the link to enable it to pop up in a new window instead of popping up in the current window?

03-08-2007, 11:06 PM
Using reponse.redirect sends a 302 to the browser.
You might as well just use a (javascript) window.open and register client script block with the URL.
That means removing the redirect.

03-09-2007, 12:42 AM
What nikkiH is trying to tell you is you can not open a a new browser window on the clients computer with server side code. So one way is javascript that will run on the clients computer. This way when he clicks the link button it will open up a new browser window.

So on my .aspx page I put my linkbutton

<asp:LinkButton ID="LinkButton1" runat="server">New Window</asp:LinkButton>

On my code behind page I put my code in the page load event.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

LinkButton1.Attributes.Add("onclick", "window.open('login.aspx','_blank')")
End Sub

Now when the client first loads the page they will be also loading the code for the new window. Try it it works!

Happying Coding

03-15-2007, 05:35 PM
Personally i would advise against using popup windows.. i believe it goes against the disability discrimination act due to it breaking the browser history

Designer Websites (http://www.designer-websites.co.uk)

03-15-2007, 05:57 PM

pop-ups and new broswer window are two different animals in my opinon. Byside how many sites have those pop-ups? That is also why on most broswers you can disable pop-ups.

I see nothing wrong with opening up a new broswer window through a link or linkbutton.