Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,
How to open a link in new window using Response.Redirect(). I want to open the page in new window using code under button_Click.
Posted
Updated 23-Jun-17 0:40am

 
Share this answer
 
One of the neatest ways I've ssen to open a new window with Response.Redirect is indicated here[^]. As it states, you cannot open a new window with the standard redirect method because of the way it works internally (i.e. it sends a special HTTP request to trigger the redirect), so you need to apply a little bit of mojo to get it working.
 
Share this answer
 
Use this code in button click event (code behind) it will open the page in new window


C#
string url = "WebForm.aspx";
            Response.Write("<script type='text/javascript'>window.open('" + url + "');</script>");
 
Share this answer
 
v2
HTML Code:
C#
<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry"

OnClick="btnNewEntry_Click" OnClientClick="aspnetForm.target ='_blank';"/>

Button Click cs file:
C#
protected void btnNewEntry_Click(object sender, EventArgs e)
{
    Response.Redirect("New.aspx");
}
 
Share this answer
 
Hi,

Please find solution at below link

Response.Redirect into a new window[^]

Thanks,
Nitin
 
Share this answer
 
Basically using code behind there is no direct way to open link in new window, but using target attribute of link you can achieve it, set target to '_blank', it will help you to open page in new window
OR
you can use JavaScript for it, window.open method will help you to do it
see below snippet
JavaScript
function openMe()
{
window.open("1.aspx",'_blank');
return false;
}
 
Share this answer
 
Use the below code to open link in new window.

Response.Write(" window.open('"+ url + "', 'window');");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900