How to use showModalDialog in

On WebForm1.aspx, I have a linkbutton to call a JavaScript function to show a modal web page, WebForm2.aspx. Like this:

function ShowNewPage()
window.showModalDialog("WebForm2.aspx","","width=400; height=200; resizable=yes; scrollbars=yes; top=300; left=300");

On WebForm2.aspx, I have a web control button. If I click on it, something weird happened. Instead of post back to the same page (WebForm2.aspx), it opens another web page, which is unexpected behavior.

Does anybody know how to fix this problem and let modal web page post back to itself?

Thanks a lot.
Who is Participating?
InteliscapeConnect With a Mentor Commented:
There is no any direct solution.

But you can work with iframes or layers.

something like this in the modal page

<iframe id = "tst" width="100%" height="100%"  src="WebForm2.aspx"> </iframe>

the rest are easy you have a full functional page and the id of the page.

i hope know its ok.

this is how in one page.

<INPUT type=textbox id=mmytext tabIndex=1>
function ShowNewPage()
mmytext.value=window.showModalDialog("page1.HTM","","width=400; height=200; resizable=yes; scrollbars=yes; top=300; left=300");
function leave(ret){
      window.returnValue = ret;
<INPUT id=button1 onclick=leave(false); tabIndex=1 type=button value=No>&nbsp;&nbsp;&nbsp;
<INPUT id=button2 onclick=leave(true); tabIndex=2 type=button value=Yes>
<div onClick="ShowNewPage()"><b>Click Here</b></div>
BruceChengAuthor Commented:
I know how to use showModalDialog. My question is, in case of .NET, if the modal page (in your case page1.HTM) post back to itself, it opens a new modaless windows.

Which is, in my example, on the opened modal window, WebForm2.aspx, if I click a button or select an new item from a drop down list, WebForm2.aspx will post back to itself automatically. At this time, instead of refreshing the same WebForm2.aspx, it opens another modaless page. How can I just refresh the same modal window page without opening a new window.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Bruce Cheng,

In the child form ,you open html view.
You will find html tag <body >

type in property,  onblur="this.focus"

this is how it looks like

<BODY  onblur="this.focus">

This is all the code you need to avoid the new windows on postback with showModalDialog:

      <base TARGET="_self">

Put this in your <head> tag on your page.

You don't need to mess with other frames. I'm glad I found this before going the frames route.

Thanks Polyktor

It is a better solution than using a empty page with a iframe.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.