By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

window.open v.s. asp.net

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
carlor wrote:
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...

Nov 19 '05 #2

P: n/a
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.

"Damien" wrote:
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...


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.