views:

260

answers:

2

I have a quite simple data capture web app.

In the main capture window, when you save a row in a UltraWebGrid, depending on certain flags two more windows open (with a ScriptManager.RegisterStartupScript).

One of the windows, works perfectly fine.

The other one, when it gets closed (by means of its own ScriptManager.RegisterStartupScript) causes the next error in Firefox IN THE MAIN WINDOW:

Sys is not defined Sys$CultureInfo$_getAbbrMonthIndex("")ScriptRe...=7c12e347 (line 6391) ? in ScriptResource.axd?d=Bx90cRohr9iY-lmxXmy5QYd7JgQApS0Xh-xBfl6hEe8d-0h4pCZYQQKgxdo97mKzaD5488jiBZ8TOSa4-cOPaw2&t=4e25e479@1()ScriptRe...=4e25e479 (line 499) [Break on this error] this._upperAbbrMonths = this...s.dateTimeFormat.AbbreviatedMonthNames);

And after this, Firefox goes crazy, tab navigation stops working, every text input in the window (including the address bar, and the search box) draw their contents as if they are selected (all at the same time) and things stop behaving quite strange. I have to close the window and reopen it, sometimes I even have to kill the process.

I've tried many things, and nothing seems to work. I compare the two aspx files in the aforementioned windows and nothing is really that different.

This is GETTING ME FREAKING CRAZY.

Anyone have had this error before? Any ideas? Hacks? Pointers?

Thank you very much.

A: 

Althought I do not know exactly why, the bug was caused by the

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CLOSE", "window.close()");

The other window has a similar thing but it didnt cause it.

I fixed it by wrapping the window.close() in a setTimeout("window.close();", 500).

I have no idea why this is happening if anyone have a clue please enlighten me.

Cheers!

Francisco Soto
+1  A: 

The short answer is that managing windows (opening and closing) in a browser is not a fun or trivial task. You have to ensure that any scripts that are executing have completed before closing the window. In your case it sounds like there was still an initialization script running while you were closing the window. At that point, the DOM is destroyed, and the script starts trying to access elements that have already been removed. The timeout is the easies hack. The better solution is to use the WebDialogWindow (also in NetAdvantage) which pops up 'windows' that are actually elements on the same page. That way you can manage it without having to rely on postbacks and script includes, and you don't have to struggle with getting data out of a separate window.