form1.target='_blank';

J

Jonathan Wood

I tried adding the subject of this post in my button's OnClientClick
property. But the result goes to the same window.

Does anyone know how to have a button (and only one button) on a form post
to itself in a new window?

And, if not, does anyone know how to cross post to another URL in a new
window?

Thanks.
 
M

Mark Rae [MVP]

[top-posting corrected]
As far as I know, window.open does a GET, and not a POST. Am I missing
something?

Yes. If you want to open a new window, you have no other choice as that
action can only be performed client-side...
 
J

Jonathan Wood

I understand it can only be accomplished client side. However, I know that
the form tag can include a TARGET="_blank" attribute and, AFAIK, that works.
So it can be accomplished. The only thing is how to make it only that way
for one button.

So I still don't see what I'm missing.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Mark Rae said:
[top-posting corrected]
As far as I know, window.open does a GET, and not a POST. Am I missing
something?

Yes. If you want to open a new window, you have no other choice as that
action can only be performed client-side...
 
S

Scott Roberts

Not sure about using target="_blank", but something I've done in the past is
go ahead and let the button post back as usual then add a startup script in
the button event handler (using RegisterClientStartupScript) to open a new
window using javascript. To pass the processed data, you can put it in an
object (or struct) and stuff it into the session, then read that session
variable from the page opened in the new window.

Just an idea. It may or may not work for your situation.


Jonathan Wood said:
I understand it can only be accomplished client side. However, I know that
the form tag can include a TARGET="_blank" attribute and, AFAIK, that
works. So it can be accomplished. The only thing is how to make it only
that way for one button.

So I still don't see what I'm missing.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Mark Rae said:
[top-posting corrected]
And, if not, does anyone know how to cross post to another URL in a
new window?

http://www.google.co.uk/search?sour...EZ_en-GBGB252GB252&q=JavaScript+"window.open"

As far as I know, window.open does a GET, and not a POST. Am I missing
something?

Yes. If you want to open a new window, you have no other choice as that
action can only be performed client-side...
 
J

Jonathan Wood

Hi Scott,
Not sure about using target="_blank", but something I've done in the past
is go ahead and let the button post back as usual then add a startup
script in the button event handler (using RegisterClientStartupScript) to
open a new window using javascript. To pass the processed data, you can
put it in an object (or struct) and stuff it into the session, then read
that session variable from the page opened in the new window.

Just an idea. It may or may not work for your situation.

Certainly more overhead than is ideal, but I suppose that would work. I'll
need to think through that a bit.

Thanks.
 
L

lemieux.raphael

Hi,

I did manage to do what you needed by addin the following line of
code to the OnClientClick of a linkbutton :

javascript:var aspnettarget;
aspnettarget=document.forms[0].target;document.forms[0].target='_blank';eval(this.href);document.forms[0].target=aspnettarget;
return false;

I guess you understand what it does, but for others who might
wonder,

aspnettarget=document.forms[0].target; keeps the default
Target of the normal ASP.NET Form
document.forms[0].target='_blank'; Changes the actual
target of the form to _Blank so it opens in a new window
eval(this.href); does a
normal postback of the button to the new target
document.forms[0].target=aspnettarget; Sets back the normal
Target for the ASP.Net Form
return false; Cancel
the "normal" call to the __Postback method since we already called it.

It worked for me just as needed... Hope this helps.

Raphaël LEMIEUX
 
L

lemieux.raphael

Hi,

I did manage to do what you needed by addin the following line of
code to the OnClientClick of a linkbutton :


javascript:var aspnettarget;
aspnettarget=document.forms[0].target;document.forms[0].target='_blank';eva­
l(this.href);document.forms[0].target=aspnettarget;
return false;


I guess you understand what it does, but for others who might
wonder,


aspnettarget=document.forms[0].target; keeps the default
Target of the normal ASP.NET Form
document.forms[0].target='_blank'; Changes the actual
target of the form to _Blank so it opens in a new window
eval(this.href); does a
normal postback of the button to the new target
document.forms[0].target=aspnettarget; Sets back the normal
Target for the ASP.Net Form
return false; Cancel
the "normal" call to the __Postback method since we already called
it.


It worked for me just as needed... Hope this helps.


Raphaël LEMIEUX
 

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

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,202
Latest member
MikoOslo

Latest Threads

Top