Opening a new window when button clicked

Discussion in 'ASP .Net' started by Jim in Arizona, Apr 24, 2008.

  1. When placing a link using html, it's easy to have a new window opened for
    the link instead of redirecting the current page to the destination. IE:

    <a href="../folder5/anotherpage.aspx" target=_blank>Another Page</a>

    I've placed a button on the page that I would like to have do the same
    thing:

    <asp:button id="btnAnotherPageLink" runat="Server" text="Another Page" />

    Protected Sub btnAnotherPageLink_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnActiveDialup.Click
    Response.Redirect("../folder5/anotherpage.aspx")
    End Sub

    This will cause the current page to navigate to the destination page. How
    can I have a new window open up and load the destination page instead?

    TIA,
    Jim
     
    Jim in Arizona, Apr 24, 2008
    #1
    1. Advertisements

  2. Jim in Arizona

    bruce barker Guest

    buttons do a form submit. you set the target on the form to control this.
    asp.net forms do not allow the target to be set, so yo must use a non-server
    form, or use javascript to set the target.

    -- bruce (sqlwork.com)
     
    bruce barker, Apr 24, 2008
    #2
    1. Advertisements

  3. After some searching, I found that adding this to the Page_Load sub did the
    trick:

    btnAnotherPageLink.Attributes.Add("onClick",
    "window.open('../folder5/anotherpage.aspx')")
     
    Jim in Arizona, Apr 24, 2008
    #3
  4. Oh! That's helpful! Thanks Mark!
     
    Jim in Arizona, Apr 24, 2008
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.