Redirect to a new window

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Basically how do I set "Target=_blank" on a url string and can it be used by
any of the following

Response.Redirect()
Server.Transfer()
PostBackURL on a link button.

So far the ONLY way I know how to do this is with an old <a href ..> tag
 
All of these are server side controls, and since it doesn't make sense
for a new window to open on the server, the target=_blank won't work.

What you can do is that you can have a mechanism through which you can
insert javascript into a page where you want a new window to open up,
and this javascript does the job for you.

- V
 
When the request is sent to the server, it's decided where the target
for the response is. As both Response.Redirect and Server.Transfer are
executed on the server, it's too late to change the target.

A postback is done to the same window, therefore a link button is not
equipped to send the post to a different window.

The LinkButton just renders as "an old <a href ...> tag" with some
Javascript, but you are limited to what the control was designed to do.
If you use the trusty old anchor tag yourself, you are not limited to a
postback.
 
You can only do target client side - so response.redirect needs to send back
javascript to open a window, transfer in theory would be the same and you
would need to interfere with postback client side to run a javascript open
window command:

<script language="javascript">
function doSomething()
{
// put some javascript code here to open a window
// Continue with submit
this.click();
}
</script>
<asp:button onmousedown="doSomething()" id="Button1" Text="Button"
runat="server"></asp:button>

.......although the result of your postback could in theory be javascript to
open a new window.

Might be easier to use a simple hyperlink and forget about postbacks,
redirects and transfers.
 
Back
Top