Tuesday, November 6, 2007

Why does my modal dialog box open another browser on submit?

Currently I am creating an application where a modal dialog box opens when the NewForm.aspx page for a WSS list is opened, to search against an external data source and pass the results back to the form (I'll let you know if this proves to be a viable design pattern!).

The default behaviour of the modal dialog has been driving me a little crazy - when the form in the ASP.Net page in the modal dialog box is submitted by clicking on a button in that page, that same form was opening in a new browser window. The dialog was also remaining open.

Finally came across the solution tucked away in a forum answer by Ken Dopierala Jr. His tip:

Remember, when you post back to a Modal page you must put: <base target="_self"> in the <head> section of the HTML on that page.

And that is all it needed to take the nastiness away, just adding that simple tag into the PlaceHolderAdditionalPageHead placeholder of the WSS page being presented in the dialog. Thanks, Ken!

6 comments:

Nemortu said...

I also have this problem and I tried using a special master with the < base target="_self" > for the modal windows but I still got the same result (another window, non-modal opens). Could you please post a code sample for the modal window (did it work for you using window.close or self.close?). I wanted now to try out the commonShowModalDialog which is the JS function used by MOSS to open the peoplepicker fro example.
(PS: I wanted the modal window to be opened from the EditForm.aspx )

Nemortu said...

Just had the time to test putting the < base target="_self" > in the PlaceHolderAdditionalPageHead instead of putting it directly in the the master I used for popups and everything worked great. Thank you for the post, it really helped!

Eric Farraro said...

This was seriously annoying me and your tip worked perfectly. I was using some crazy iframe work around but this is so much better. Thanks!

NLV said...

This just worked brilliantly. Thanks for sharing it.

Unknown said...

Thanks a lott...great help

Unknown said...

this works amazing ..thanks for great help