Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening a new window when button clicked

0 views
Skip to first unread message

Jim in Arizona

unread,
Apr 24, 2008, 2:38:54 PM4/24/08
to
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


bruce barker

unread,
Apr 24, 2008, 3:13:00 PM4/24/08
to
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

unread,
Apr 24, 2008, 6:14:13 PM4/24/08
to

"bruce barker" <bruce...@discussions.microsoft.com> wrote in message
news:31A7A52C-5278-4856...@microsoft.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:

btnAnotherPageLink.Attributes.Add("onClick",
"window.open('../folder5/anotherpage.aspx')")


Mark Rae [MVP]

unread,
Apr 24, 2008, 6:28:58 PM4/24/08
to
"Jim in Arizona" <tilt...@hotmail.com> wrote in message
news:ubwPOilp...@TK2MSFTNGP02.phx.gbl...

> 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')")


Or alternatively:

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

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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jim in Arizona

unread,
Apr 24, 2008, 6:43:05 PM4/24/08
to
"Mark Rae [MVP]" <ma...@markNOSPAMrae.net> wrote in message
news:OuVfVqlp...@TK2MSFTNGP05.phx.gbl...

Oh! That's helpful! Thanks Mark!


Mark Rae [MVP]

unread,
Apr 24, 2008, 7:26:58 PM4/24/08
to
"Jim in Arizona" <tilt...@hotmail.com> wrote in message
news:OXEoWylp...@TK2MSFTNGP02.phx.gbl...

> Oh! That's helpful! Thanks Mark!

Always a pleasure, never a chore... :-)

0 new messages