Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pop Up In New Window

    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
    Response.Redirect("http://www.bbc.co.uk")
    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?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    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
    Code:
    <asp:LinkButton ID="LinkButton1" runat="server">New Window</asp:LinkButton>
    On my code behind page I put my code in the page load event.
    Code:
    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

  • #4
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    What?

    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.


  •  

    Posting Permissions

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