window.open v.s. asp.net

G

Guest

Hi there,

I have a form that contains a link button. When the user clicks the link
button I need to enable a couple of other buttons on the page and open a new
browser window giving it focus (keeping it on top). I have most of it working
but I can't get it all working. I can either have the window open and disable
the buttons with the new window in the background, or I can have the new
window in the foreground but not be able to disable the buttons. Here's why:

In the pageLoad of the main form, I add an onclick attribute to the link
button that creates the new browser window using window.open:

lbLinkButton.Attributes.Add("onclick", "var w=window.open('" &
"newPage.aspx" & "'); w.focus();")

When the user clicks on the link button, the window.open gets fired and then
the link button's click event fires and I enable the other buttons on my
page. The problem is that the new window appears on top for a brief period
then disappears to the background (I assume when the rest of the code behind
for the main form executes).

I was able to get the new browser window to stay in the foreground by adding
"return false" to the above attribute as in:

lbLinkButton.Attributes.Add("onclick", "var w=window.open('" &
"newPage.aspx" & "'); w.focus(); return false;")

The problem I now have with the return false is that execution doesn't
return to the main form's code behind; the link button's click event never
gets trapped.

Does anyone know of a solution to this problem?


Thanks,

Carlo.
 
D

Damien

carlor said:
Hi there,

I have a form that contains a link button. When the user clicks the link
button I need to enable a couple of other buttons on the page and open a new
browser window giving it focus (keeping it on top). I have most of it working
but I can't get it all working. I can either have the window open and disable
the buttons with the new window in the background, or I can have the new
window in the foreground but not be able to disable the buttons. Here's why:

In the pageLoad of the main form, I add an onclick attribute to the link
button that creates the new browser window using window.open:

lbLinkButton.Attributes.Add("onclick", "var w=window.open('" &
"newPage.aspx" & "'); w.focus();")

When the user clicks on the link button, the window.open gets fired and then
the link button's click event fires and I enable the other buttons on my
page. The problem is that the new window appears on top for a brief period
then disappears to the background (I assume when the rest of the code behind
for the main form executes).

I was able to get the new browser window to stay in the foreground by adding
"return false" to the above attribute as in:

lbLinkButton.Attributes.Add("onclick", "var w=window.open('" &
"newPage.aspx" & "'); w.focus(); return false;")

The problem I now have with the return false is that execution doesn't
return to the main form's code behind; the link button's click event never
gets trapped.

Does anyone know of a solution to this problem?
Could you not, instead of hooking into the onclick event, have the
following within the button click event:

Response.RegisterClientScriptBlock("PopNewWindow","<script
type=""text/javascript"">var w=window.open('newPage.aspx');
w.focus();</script>")

Which would then open the window after the postback has completed...
 
G

Guest

Hi Damien,

Thanks for the reply but unfortunately it didn't work. The page did not
open. BTW, I had to change from "Response" to "Page".

Thanks,

Carlo.
 
Joined
Apr 22, 2008
Messages
2
Reaction score
0
try this. May work for you

lnkbutton.onClientClick="var w=window.open('" &
> "newPage.aspx" & "'); w.focus(); return false;"
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top