Response.Redirect to new window in ASP.NET

In this post, I will show you how to open a new window in the browser using Response.Redirect Check the following code it’s self-explanatory. If you have any issue comments in the comment box.

<%@ Page Language="C#" AutoEventWireup="true"  
CodeFile="RedirectToAnotherPage.aspx.cs" Inherits="RedirectToAnotherPage" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
<html xmlns="" >  
<head runat="server">  
<title>Untitled Page</title>  
<form id="form1" runat="server">  
<h1>Main Window</h1>  
<asp:Button ID="btn" runat="server" Text="Redirect" OnClick="btn_Click" />  
using System;  
using System.Data;  
using System.Configuration;  
using System.Collections;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  

public partial class RedirectToAnotherPage : System.Web.UI.Page  
protected void Page_Load(object sender, EventArgs e)  

public static class ResponseHelper  

   public static void Redirect(string url, string target, string windowFeatures)  
       HttpContext context = HttpContext.Current;  

       if ((String.IsNullOrEmpty(target) ||  

           target.Equals("_self", StringComparison.OrdinalIgnoreCase)) &&  

           Page page = (Page)context.Handler;  
           if (page == null)  
               throw new InvalidOperationException(  
                   "Cannot redirect to new window outside Page context.");  
           url = page.ResolveClientUrl(url);  

           string script;  

           if (!String.IsNullOrEmpty(windowFeatures))  
               script = @"""{0}"", ""{1}"", ""{2}"");";  

               script = @"""{0}"", ""{1}"");";  


           script = String.Format(script, url, target, windowFeatures);  







protected void btn_Click(object sender, EventArgs e)  
   ResponseHelper.Redirect("popup.aspx", "_blank", "menubar=0,width=100,height=100");  
Next Post Previous Post
No Comment
Add Comment
comment url