Response.Redirect to a new window

While it’s not possible to use the provided method to redirect it to a new window, you can achieve the desired behavior by:

1) Changing the form.target to ‘_blank’

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="theForm.target ='_blank';"
	OnClick="btnSubmit_Click" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
	Response.Redirect("Handler.ashx");
}

2) Or using Javascript window.open

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
	string script = "window.open('Handler.ashx', '_blank');";
	ScriptManager.RegisterStartupScript(this, typeof(Page), "Redirect", script, true);
}

You can also call a Javascript function in client-side without doing the post-back on server-side.

As you noticed, there are several ways to do the redirection to a new window in ASP.NET. The best way only depends on what your scenario is.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s