Opening a new window when button clicked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim in Arizona

    Opening a new window when button clicked

    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.asp x" target=_blank>A nother Page</a>

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

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

    Protected Sub btnAnotherPageL ink_Click(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles btnActiveDialup .Click
    Response.Redire ct("../folder5/anotherpage.asp x")
    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


  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: Opening a new window when button clicked

    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)


    "Jim in Arizona" wrote:
    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.asp x" target=_blank>A nother Page</a>
    >
    I've placed a button on the page that I would like to have do the same
    thing:
    >
    <asp:button id="btnAnotherP ageLink" runat="Server" text="Another Page" />
    >
    Protected Sub btnAnotherPageL ink_Click(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles btnActiveDialup .Click
    Response.Redire ct("../folder5/anotherpage.asp x")
    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
    >
    >
    >

    Comment

    • Jim in Arizona

      #3
      Re: Opening a new window when button clicked [RESOLVED]


      "bruce barker" <brucebarker@di scussions.micro soft.comwrote in message
      news:31A7A52C-5278-4856-8C3F-EFF9D1A203A6@mi crosoft.com...
      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)
      >
      >
      After some searching, I found that adding this to the Page_Load sub did the
      trick:

      btnAnotherPageL ink.Attributes. Add("onClick",
      "window.open('. ./folder5/anotherpage.asp x')")




      Comment

      • Mark Rae [MVP]

        #4
        Re: Opening a new window when button clicked [RESOLVED]

        "Jim in Arizona" <tiltowait@hotm ail.comwrote in message
        news:ubwPOilpIH A.5096@TK2MSFTN GP02.phx.gbl...
        After some searching, I found that adding this to the Page_Load sub did
        the trick:
        >
        btnAnotherPageL ink.Attributes. Add("onClick",
        "window.open('. ./folder5/anotherpage.asp x')")

        Or alternatively:

        <asp:Button ID="btnAnotherP ageLink" runat="server" Text="Another Page"
        OnClientClick=" window.open('../folder5/anotherpage.asp x');return false;" />

        Don't forget the semi-colons at the end of each JavaScript statement...


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • Jim in Arizona

          #5
          Re: Opening a new window when button clicked [RESOLVED]

          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:OuVfVqlpIH A.4848@TK2MSFTN GP05.phx.gbl...
          "Jim in Arizona" <tiltowait@hotm ail.comwrote in message
          news:ubwPOilpIH A.5096@TK2MSFTN GP02.phx.gbl...
          >
          >After some searching, I found that adding this to the Page_Load sub did
          >the trick:
          >>
          >btnAnotherPage Link.Attributes .Add("onClick",
          >"window.open(' ../folder5/anotherpage.asp x')")
          >
          >
          Or alternatively:
          >
          <asp:Button ID="btnAnotherP ageLink" runat="server" Text="Another Page"
          OnClientClick=" window.open('../folder5/anotherpage.asp x');return false;"
          />
          >
          Don't forget the semi-colons at the end of each JavaScript statement...
          >
          >
          --
          Mark Rae
          ASP.NET MVP
          http://www.markrae.net
          Oh! That's helpful! Thanks Mark!


          Comment

          • Mark Rae [MVP]

            #6
            Re: Opening a new window when button clicked [RESOLVED]

            "Jim in Arizona" <tiltowait@hotm ail.comwrote in message
            news:OXEoWylpIH A.3960@TK2MSFTN GP02.phx.gbl...
            Oh! That's helpful! Thanks Mark!
            Always a pleasure, never a chore... :-)


            --
            Mark Rae
            ASP.NET MVP


            Comment

            Working...