in

ASP.NET Weblogs

Datagrid Girl

Marcie, ASP.NET Datagrid Blogger Girl

showModalDialog and postbacks in ASP.NET

I learned something new today that my coworker Dennis spent several agonizing hours trying to solve.  He was using window.showModalDialog to open a modal window on the client from Javascript, but whenever that page posted back, it would spawn off a new window.  (A normal window.open worked fine, this was only a problem for modal windows).  Some searching turned up several people with the same problem, and the solution once found (here), was quite simple:  just include this line in the < HEAD > html of the modal window:

<base target=_self>

Hope this saves someone else some time!
Marcie

Comments

 

bestcomy said:

It's not work under IE 5.0
August 11, 2005 9:07 PM
 

Marcie said:

Interesting, it works great for us under IE 6, and both <base> and showModalDialog were around in IE 5, so I'm surprised that it doesn't work there.
August 11, 2005 9:13 PM
 

Ron Buckton said:

The standard solution I always employed was to load a dummy page in the modal dialog that only writes out an IFRAME to the window (height/width 100% and no border). The IFRAME is given a SRC tag of the actual page to be viewed. In this case, postbacks and whatnot will work fine in a showModalDialog or showModelessDialog.
August 11, 2005 11:42 PM
 

MatHertel said:

I've run into this problem too and did the following:
* when entering the page i give window.name a unique name.
* i set the target of my links to this name

btw:
window.navigate(newUrl) or
window.location.href = newUrl will open a new window.
use window.open(newUrl, window.name) instead.

and:
disable all caching for pages that are used in modal dialogs. When IE has to show a url that's cached it loads from the cache without asking the server in some circumstances.

better than ron's approach but I can't check whether it works fine with IE 5.x
(got an upgrade some years ago)
August 13, 2005 8:22 AM
 

Shake said:

Thank you so much MatHertel the window.name works great!!!

Btw, <base target=_self> didn't work for me :S
August 25, 2005 1:07 PM
 

Elen said:

It solve my problem when i was working on progress bar with VB.net.

Thank a lot.

July 4, 2007 5:32 PM
 

Anand said:

I want to write the AJAX response in the Modal Window. Has any one got the  solution for this?

Thanks In advance

July 13, 2007 5:12 AM
 

Neeraj said:

Thanks Marcie for this solution.

<base target="_self" />

My team must have spent some 30 man hours on this problem.

btw, I saw some comments that this solution didn't work for them... Make sure they are using window.showModalDialog and not window.open.

August 9, 2007 4:16 PM
 

Pradeep Bisht said:

Exact solution

thanks

August 16, 2007 3:07 AM
 

Pavel said:

Thanks Marcie,

I spent 6 hours on this problem

and <base target="_self" />  resolve my problem

August 17, 2007 6:46 AM
 

Dan O'Connell said:

Perfect.  Similar story to others: wasted a few hours on this, until I saw your solution.  Thanks.

August 20, 2007 12:42 PM
 

Brent Campbell said:

Unbelievable, never thought that would be the resolution, again, more than a few hours wasted and thinking there was no solution. Cheers!

September 7, 2007 6:27 AM
 

Ali said:

Wasted 5 minutes.  Did a google search.  Found this great article.  Very happy that I did not waste 30 man hours.  Thanks everyone.

September 7, 2007 6:20 PM
 

Mahesh Nihalani said:

Worked great... Thanks...

September 12, 2007 4:51 PM
 

Karu Anna said:

Base target solution worked fine for me after trying other things for hours. Thanks for your effort to find and post this solution.

September 26, 2007 7:06 AM
 

Suresh said:

thanks .. saved my day.

September 27, 2007 5:33 PM
 

Indika said:

Worked like a charm !

:-)

September 28, 2007 3:25 AM
 

Kenny said:

Thanks for posting this - it works

October 1, 2007 11:42 AM
 

Alberto said:

Works for me!!!

Uhul!!!

Thanks Marcie!

October 3, 2007 11:07 AM
 

Hariprasad said:

Great solution,

really u saved my time. I was breaking my head since 2 days..

once again thanks,

hari

October 9, 2007 3:24 AM
 

DotNetter said:

Works fine...  Good article...  Thanks a lot...

October 16, 2007 2:12 AM
 

Anand said:

Working Fine

thnx

November 14, 2007 11:10 AM
 

Naman said:

Why it is not solving my issue.. I have grid in modal popup.. When i click Edit button it is getting postback. All code gets executed but on poup page it is not coming in edit mode.. I have edit item template defined... and it is not visible on screen on click of edit button..

What to do ....????

November 19, 2007 9:25 AM
 

veeru said:

Fantastic,

I was about to move to window.open.

saved my day

Thanks

November 28, 2007 3:12 AM
 

LAKSMANAN said:

<base target=_self>

Works fine..

but the title of IE goes away.. when is posted...

is there any solution ? that will not make any change in the iE title

December 3, 2007 4:58 AM
 

Dave Johnson said:

Another happy customer! <BASE Target=_self> works fine for me.

Thanks for saving me a lot of time.

January 7, 2008 5:54 AM
 

Amit said:

thanks a lot , it is working fine. I spent three hours and breaking my head

January 11, 2008 4:57 AM
 

Neelima said:

It's not working for me.

I'm using master pages.

January 23, 2008 4:47 AM
 

Neelima said:

It's not working for me.

I'm using master pages.

function VendorContact(VendorId)

   {

     Options = "dialogTop:50px; dialogLeft:50px;dialogWidth:340px;dialogHeight:155px;help:no;scroll:no;status:no"

     OpenReportJS = window.showModalDialog("VendorContact.aspx?VID=" + VendorId,"_blank",Options) ;

   }  

And i'm getting the vendorid from xsl.

I got an error like "Object doesn't support this action".

I have been trying htis from past 5 hours.

Please help me out in giving the solution.

January 23, 2008 5:30 AM
 

Roberto said:

thanks a lot , it is working fine. I spent three hours and breaking my head

February 5, 2008 5:25 AM
 

Frederick Chapleau weBlog on IT. said:

The answer on how to do postback in modal / modaless diaglogs. weblogs.asp.net/.../archive

February 6, 2008 12:24 AM
 

SAV said:

You've saved my life!

Thanks

February 7, 2008 2:36 AM
 

Stronghold said:

Very good solution - i have been fighting with this several times - great - thanks :)

February 7, 2008 6:26 AM
 

Len said:

<base target="_self" />

worked great

Many thanks

February 15, 2008 5:03 PM
 

Panya said:

Love you marcie.

You save my day.

February 23, 2008 2:07 PM
 

Renz said:

Really worked..Thanks :)

February 25, 2008 1:58 AM
 

Beatriz said:

Lots of thanks!!!

Be careful, because it doesn't runs if smartnavigation is true.

Sorry for my english.... :(

March 9, 2008 5:08 PM
 

Dan said:

When I use <base target="_self" /> I can't use the Virtual Earth Mapping control under IE 6

March 24, 2008 3:14 PM
 

Irwin Y. Quintana Fitta said:

Thank you Marcie, you save my life.

Now I have a problem when I'm trying to access opener's controls from the child modal window but this problem doesn't appear when the child window was open by using "window.open" instead "window.showModalDialog".

Do anybody know how to solve this issue?

Thanks in advance.

March 26, 2008 10:31 AM
 

Sathish said:

Thanks a lot Marcie!

Good solution for this issue.

Thanks a lot again.

For those who need information about  "showModalDialog" check the following link

msconline.maconstate.edu/.../jsdhtml07-05.htm

March 28, 2008 5:16 AM
 

Ryan said:

What an easy solution, I was running out of ideas!  Thank you.

April 8, 2008 4:30 PM
 

SP said:

It worked for me. Great solution. I was breaking my head on this for last two days. Thank You.

April 24, 2008 4:27 PM
 

T said:

Thank you very much.

May 12, 2008 10:06 PM
 

mahdokht said:

thanx u alot , it was great

May 21, 2008 7:24 AM
 

eminently_addictive said:

yes <base target="_self" > works for submitting a request through a modal window without opening a new window.

But make sure you DO NOT HAVE any other property set like document.forms[0].target  = _self (I was doing it and it was not working)

Another thing i noticed is title disappears after the modal window refreshes !! someone mentioned it in the post but no one answered it ?? can anyone provide some inputs on it ??

May 21, 2008 4:19 PM
 

eminently_addictive said:

To make sure the title does not disappear after a request is made from a modal window ... all you have to do is make sure the title is the first tag after ur head tag ..

<head>

<title>

ur title

</title>

<base target=_self>

.

.

</head>

Hope this helps anyone ... and thanks to all who posted their comments.

May 21, 2008 4:32 PM
 

Deo said:

Hey thanks....

no matter what they said about your solution, it is the simplest and for me it's the best.

June 6, 2008 11:51 AM
 

Joseph John said:

it worked for me. Great solution. I spent several hours and nothing. Thank you so much.

June 16, 2008 6:14 PM
 

Norman said:

Thanks buddy..it worked for me

I was using .net 3.5 , C# asp.net

June 25, 2008 6:41 AM
 

Harsh said:

Thanks a lot...

it was of a gr8 help 2 me...

July 23, 2008 9:49 AM

Leave a Comment

(required)  
(optional)
(required)  
Add