Open new window with Response.Redirect() in

Today I want share with you a very interesting tips using Response.Redirect(). In there are various ways to move from one page to another. Mostly used.
  1. Response.Redirect()
  2. Server.Transfer()
 But unfortunately you cant open a new window with those two methods. Which is possible with anchor link like <a href="#" target="_blank" >. When goggling I find that most of the answer is it is not possible or to make it possible you would add JavaScript method to using it. But I don't want this, at last I found two approaches. Now I want to share with these two approaches with  Response.Redirect() and  Server.Transfer().

First approach(easiest way):

Just use the OnClientClick event of the button. 
<asp:Button ID="btnHome" runat="Server" CssClass="button" Text="Go home"
OnClick="btnHome_Click" OnClientClick=" ='_blank';"/>
protected void btnHome_Click(object sender, EventArgs e)

If you want to access the form inside the Master page to Child page level


This code will find the controls collection and find your form and allow you to get access to the client id so you can be sure you have proper naming of it for the JavaScript to function correctly. Make sure you replace "form1" with whatever you have your parent form id="name" set to inside your Master’s page markup.

For multiple buttons on a single page and only want a specific button to launch into a new window.

<asp:Button ID="btnHomePage" runat="Server" CssClass="button" Text="Your home"
OnClick="btnHomePage_Click" OnClientClick=" ='_self';"/>

protected void btnHomePage_Click(object sender, EventArgs e)
   //Do normal code for postback

For more details.visits

In next post I will share with you another approach to open new window using response.redirect() insha Allah.


Na Manasu said…
Hay the solution for opening New Window using response.redirect is in this post please have a look

it worked for me
Vinay said…
For the same Situation but button is present in Grid view as link Button...
Please Provide the Solution as Early as Possible.

Thanks in Advance
Response.Redirect()& Server.Transfer() both are using transfer one page to another but in response.redirect the browser url changes to targeted page as well as in server.transfer the url remains same.

Popular posts from this blog

How can I get a value of a property from an anonymous type (C#)

The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

"This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."