Monday, May 13, 2013

Response.Redirect to New Window


Response.Redirect to New Window


If you have multiple buttons and you want one or some buttons to redirect to a page in another window, use following code.

1. Button redirecting to a page in new window

<asp:Button ID="btnNewWindow" runat="Server" Text="New Window"

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

protected void btnNewWindow_Click(
object sender, EventArgs e)
{
Response.Redirect("
NewPage.aspx");
}


2. Button redirecting to a page in same window


<asp:Button ID="btnSameWindow" runat="Server" Text="Same Window"

OnClick="btnSameWindow_Click" OnClientClick="aspnetForm.target ='_self';"/>

protected void btnSameWindow_Click(
object sender, EventArgs e)
{
Response.Redirect("
SomePage.aspx");
}

It is imperative that you add OnClientClick="aspnetForm.target ='_self';" 
on the button in which you want to redirect to a page in Same Window, otherwise
all Response.Redirect in this page will start to open in New Window.

No Java scripts :)

No comments:

Post a Comment