4533 Views // 0 Comments // Not Rated

Opening A Window With Window.Open From A Window Opened With Window.Open (And AJAX)

Using ASP.NET 2.0 and ASP.NET AJAX has finally given me a server-side method to perform a window.open that I am comfortable with:

Code Listing 1

  1. ScriptManager.RegisterStartupScript(this, typeof(Page), Guid.NewGuid().ToString(), "window.open('IAmAPopup.aspx', null, '[window features]');", true);

Throw a ScriptManager on your page, and place this code inside a click event, and if the element you're clicking is inside an Update Panel, then you've pretty much got it.


What we've been noticing is that when the above code is running on a window that has been popped up in this manner, then window.open call does a redirect instead of opening a new window! This might be old news for people who are JavaScript gurus (which I am certainly not). But it seems as though when a window was been opened with a call to the page's Script Manager, that page is trying to own all popups.

I haven't investigated this thoroughly (since we had to get this into prod) but the behavior was fairly pervasive thoughout the app.

In order to get around this, I had to explicity tell JavaScript to call window.open on a new object. Here's the updated call, with a varaible declared before the window.open and used as the second argument:

Code Listing 2

  1. ScriptManager.RegisterStartupScript(this, typeof(Page), Guid.NewGuid().ToString(), "var popup; window.open('IAmAPopup.aspx', popup, '[window features]');", true);

What this does is forces a new window to be popped up. It also gives us the opportunity to keep a line of communication open between the parent and the child windows. Not a big deal, but yet another workaround for the unpredictable effect AJAX seems to be having on standard web development and assumed behaviors (and my life).

4 Tags

No Files

No Thoughts

Your Thoughts?

You need to login with Twitter to share a Thought on this post.