Redirect to a new window

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
 
V

V

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
 
G

Guest

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.
 
J

John Timney \(MVP\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top