Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Opening a new window when button clicked

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim in Arizona - 24 Apr 2008 19:38 GMT
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 - 24 Apr 2008 20:13 GMT
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)

> 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:
[quoted text clipped - 16 lines]
> TIA,
> Jim
Jim in Arizona - 24 Apr 2008 23:14 GMT
> 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] - 24 Apr 2008 23:28 GMT
> 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...

Signature

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

Jim in Arizona - 24 Apr 2008 23:43 GMT
>> After some searching, I found that adding this to the Page_Load sub did
>> the trick:
[quoted text clipped - 9 lines]
>
> Don't forget the semi-colons at the end of each JavaScript statement...

Oh! That's helpful! Thanks Mark!
Mark Rae [MVP] - 25 Apr 2008 00:26 GMT
> Oh! That's helpful! Thanks Mark!

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

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.