Home > Backend Development > C++ > How to Open a New Browser Window Using Response.Redirect in ASP.NET?

How to Open a New Browser Window Using Response.Redirect in ASP.NET?

Mary-Kate Olsen
Release: 2025-01-08 14:47:41
Original
548 people have browsed it

How to Open a New Browser Window Using Response.Redirect in ASP.NET?

Use Response.Redirect to open the page in a new browser window

This article describes how to use ASP.NET's Response.Redirect method to jump to a new page and have it open in a new browser window without using JavaScript to register a script.

Just add attributes "OnClientClick='aspnetForm.target = '_blank';'" to your server-side link or button. This will instruct the browser to open the link target in a new browser tab.

For example:

<code><asp:LinkButton ID="myButton" OnClick="myButton_Click" OnClientClick="aspnetForm.target='_blank';" runat="server" Text="点击我!"></asp:LinkButton></code>
Copy after login

On the server side, execute the Response.Redirect("MyPage.aspx") code in the OnClick event handler and the page will open in a new window.

However, this setting may cause all links on the page to open in new windows. To resolve this issue, add the following script to the head of the popup window:

<code class="language-javascript">function fixform() {
    if (opener.document.getElementById("aspnetForm").target != "_blank") return;
    opener.document.getElementById("aspnetForm").target = "";
    opener.document.getElementById("aspnetForm").action = opener.location.href;
}</code>
Copy after login

and add <body> in the "onload='fixform()'" tag of the popup window. This ensures that when the popup is closed, the form's target is reset to its original value.

Through the above methods, you can effectively control page jumps and avoid the problem of all links opening in new windows, thereby achieving more sophisticated page jump management.

The above is the detailed content of How to Open a New Browser Window Using Response.Redirect in ASP.NET?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template