.NET Framework Bookmark and Share   
 index > JScript for the .NET Framework > Parent window's load event not fired after closing a ShowModialDialog called window.
 

Parent window's load event not fired after closing a ShowModialDialog called window.

Hi

I am opening a page by window.ShowModalDialog, I open this page for two scenarios one for adding a record in db and one for editing a record. The querystring for both cases is different.

I have two functions one for opening the page for adding and one for opening the page for editing.

Right after the statement for opening the page in modalDialoog state I call window.location.reload so that the parent page can be refreshed.

I am facing a strange problem of parent window's load not being fired after closing a ModalDialog page opened for edit.

The page does get refreshed after closing the ModalDialog window opened for adding the record.

The code I am using for opening for adding and editing is as follows.

function btnOpenForEdit(customerId)

{

var sCustomWinParams = "dialogWidth:725px0px;dialogHeight:525px0px;help:0;status:0;scroll:0;center:1;resizable:no;"

var sPath="MyPage.aspx?CustomerId=" + customerId;

var args;

var objlookup = window.showModalDialog(sPath,args,sCustomWinParams);

window.location.reload();

}

function btnOpenForAdd()

{

var sCustomWinParams = "dialogWidth:725px0px;dialogHeight:525px0px;help:0;status:0;scroll:0;center:1;resizable:no;"

var sPath="MyPage.aspx?ProductId=" + document.getElementById("hdnProductId").value;

var args;

var objlookup = window.showModalDialog(sPath,args,sCustomWinParams);

window.location.reload();

}

I'll be greatful for help.

Regards,

Haris Munawar

HarisM

Can you show us how you assign a function to the onload event?

Can you place a simple alert at the beginning of the onload code to confirm that the code doesn't run in the case of the edit operation?

Anthony Jones

Hi

I simply have a Page Load function bound to the page load event.

In case of window.location.reload called after the showmodaldialog is closed that was opened for editing, the page doesn't post backs.

I cant understand what do you mean by having an alert on load as the load event function on the server side.

I have tried to debug javascript and it shows that in both cases the window.location.reload being called.

May be it has something to do with the fact that I am opening the ModalDialog window from another windows that is opend as ModalDialog.

Regards,

Haris Munawar

HarisM

The problem when discussing clientside Javascript issues is that you need to be clear where the code you are having problems with is. The window object in Javascript clientside has a onload event. Since the subject says "parents window load event not firing"its easy to think that you are refering to the client window event. After all the on the server we refer to it as the Page Load event which is entirely different.

add this to your body element:-

<body onload="alert('Loading')" . . .

I suspect you'll get that every time there is a postback or you do a reload.

I also suspect that in some case the content for the page is being supplied by the local cache.

Get this tool:- Fiddler

This will show you everything that goes on between the client and server.

When you close your edit box do you see a request to your parent page going to the server?

Anthony Jones

Hi

sorry for that as I have just jumed into web dev from desktop apps.

I hvae associated a javascript code to the onload event, its does executes when sowmodaldialog is closed after adding the record....and not for when showmodaldialog is closed opened for editing.

I have tried the tool you mentioned....I cant see from where to add sessions into it as it is not tracking sessions itself...but from the behavior that onload event is not firing on the client side indicates that pos back is not occuring..

Regards,

Haris Munawar

HarisM

Is this running from a site or the developer web server of Visual studio?

The next place you should consider placing an alert is just prior to the call to reload in the edit function.

Have you cleared the 'Disable debugging' check boxes in the IE Options advanced settings?

Anthony Jones

Hi

Yes, its running from the VS web dev server.

I have placed two alerts one before the reload statement and one after the reload statement. both of them executed.

The checkboxes are cleared for disable script debugging.

But still its not reloading .....

Regards,

Haris Munawar

HarisM
Can you try a very simple test?

Use window.open instead of modal dialogs and check the result.

Usually, a browser would not let you work on background windows from a modal window, even by using scripts to do that.
Colnaghi
HarisM wrote:

May be it has something to do with the fact that I am opening the ModalDialog window from another windows that is opend as ModalDialog.


I just read your comment. It seems that you gave yourself the answer.

You can't call the reload() from a ModalWindow that was open by another modal window.



Acctually this is a misbehavior that the browser shouldn't allow you to do. You can't move the focus away from a modal window, but it is allowing you to do that by opening another modal window over it.


I really hate modal windows by the way . Some browsers like firefox doesn't support modal at all (you need to simulate it with divs or forget about it completely).

Colnaghi
Roberto Colnaghi Jr wrote:
HarisM wrote:

May be it has something to do with the fact that I am opening the ModalDialog window from another windows that is opend as ModalDialog.


I just read your comment. It seems that you gave yourself the answer.

You can't call the reload() from a ModalWindow that was open by another modal window.



Acctually this is a misbehavior that the browser shouldn't allow you to do. You can't move the focus away from a modal window, but it is allowing you to do that by opening another modal window over it.

Nice catch.

Roberto Colnaghi Jr wrote:

I really hate modal windows by the way . Some browsers like firefox doesn't support modal at all (you need to simulate it with divs or forget about it completely).

http://developer.mozilla.org/en/docs/DOM:window.showModalDialog

Anthony Jones

Hi

See, I think the scenario is little misunderstood,

I have a normal window from which a modaldialog windowthat is showing a grid with records and allows to edit and insert records. This window opens another modaldialog window on it once for editing and once for adding records and calls window.location.reload right after the statement for opening the modaldialog window for record adding/editing.

The problem is that whenmodaldialog window is opened for adding, the grid window's experiences a post back but post back does not occures when it calls window.location.reload after the record adding/edintg modaldialog window is closed for the other case.

Even if what you are saying is correct then why it only happens for the editing scenario.

But I have found a solution for this. I have added an asp button on the grid window and applied it the hidden style. and instead of calling the window.location.reload I call the click event of this button after the record adding/editing window is closed. The post back occurs in both cases.

Regards,

Haris Munawar

HarisM
Anthony Jones wrote:

Roberto Colnaghi Jr wrote:

I really hate modal windows by the way . Some browsers like firefox doesn't support modal at all (you need to simulate it with divs or forget about it completely).

http://developer.mozilla.org/en/docs/DOM:window.showModalDialog

Remember that not everything on Mozilla dev docs are acctually implemented. It seems that showModalDialog is an example of it.

Try open the link you posted on Firefox.

You have modal windows on IE and Safari. You can't use it on Opera and FireFox.

Colnaghi

Sorry Haris, it's a little bit difficult to understand the whole problem without some code snippets.

But I'm glad you've founda workaround solution.

Colnaghi
Roberto Colnaghi Jr wrote:
Anthony Jones wrote:

Roberto Colnaghi Jr wrote:

I really hate modal windows by the way . Some browsers like firefox doesn't support modal at all (you need to simulate it with divs or forget about it completely).

http://developer.mozilla.org/en/docs/DOM:window.showModalDialog

Remember that not everything on Mozilla dev docs are acctually implemented. It seems that showModalDialog is an example of it.

Try open the link you posted on Firefox.

You have modal windows on IE and Safari. You can't use it on Opera and FireFox.

Works fine for me. You did notice this note in the documentation "Support added to Firefox in Firefox 3. "

Anthony Jones

Hi

See, I think the scenario is little misunderstood,

I have a normal window from which a modaldialog windowthat is showing a grid with records and allows to edit and insert records. This window opens another modaldialog window on it once for editing and once for adding records and calls window.location.reload right after the statement for opening the modaldialog window for record adding/editing.

The problem is that whenmodaldialog window is opened for adding, the grid window's experiences a post back but post back does not occures when it calls window.location.reload after the record adding/edintg modaldialog window is closed for the other case.

Even if what you are saying is correct then why it only happens for the editing scenario.

But I have found a solution for this. I have added an asp button on the grid window and applied it the hidden style. and instead of calling the window.location.reload I call the click event of this button after the record adding/editing window is closed. The post back occurs in both cases.

Regards,

Haris Munawar


Hi, I have a same requirement in which I'm opening a new window from a page that takes a value and loads grid based on that value from the main page .In this Grid, there is a field with a hyperlink that opens another window.
Now the problem is that I'm using a window.ShowmodalDialog() from the main page and it is loading /hitting the server only for the 1st time and there after executing the client side script only.
If i replace it with window.open() every thing works fine.But I want the popup window to be a modal dialog only.Can you please explain how you have added the button in grid and doing the post back to the page.
Thanks in advance.
Swathi123

You can use google to search for other answers

Custom Search

More Threads

• Help with menu item
• How to add an application mapping in IIS programmatically
• Printing with Landscape and 'Shrink-to-Fit' options in IE6 and IE7
• looping
• help with context menu on Grid
• How to get an out param from COM using JavaScript or JScript
• how to disable save button once clicked
• Help with IE Mem Leak
• Page not displaying in Iframe
• How to freeze columns in datagrid