window.showModalDialog() works perfect, but returning to parent-page doesnot

C

Curious Trigger

Hi there,

programming with Visual Studio 2005 and ASP.NET 2.0 I want to open a modal
dialog from Default.aspx.
I searched the net and many newsgroups but I couldn't find any solution.

First I tried using two aspx pages with standard controls and all those
post-backs and their attributes OnClientClick. Since this didn't work, i
reduced it to a default.aspx page opening a pure html-page as a modal
dialog.

On the second form I am using a input control of type "submit" and a little
client side script "Sub Submit1_onclick" which sets the return value and
calls "window.close()". But instead of closing the modal dialog and
returning to the caller window, it opens a new internet explorer instance
showing the same controls as the modal dialog window. Very annoying!

All I can do to close the modal dialog is clicking the white cross on the
red background in the right corner of the dialog's window. This will close
the dialog and return to the caller's window but has several drawbacks: the
return value gets lost and the user cannot choose between Ok and Cancel.

Here's my code:
======== Default.aspx =====================================
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta content="text/VBScript" http-equiv="content-script-type" />
<title>Main Page</title>
<script language="vbscript" type="text/vbscript">

Sub Button2_onclick
Dim Result 'as string
Result = window.showModalDialog("StandardHtmlPage.htm",
"","help:no;status:no;unadorned:yes")
window.alert("Dialog Result = '" & Result & "'")
End Sub

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
The Main Page - please choose a command<br />
&nbsp;<input id="Button2" type="button" value="HTML page with
Standard HTML-controls" />

</div>
</form>
</body>
</html>



======== StandardHtmlPage.htm =====================================
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="StandardHtmlDialog.aspx.vb" Inherits="StandardHtmlDialog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta content="text/VBScript" http-equiv="content-script-type" />
<title>No ASP.NET!</title>
<script language="vbscript" type="text/vbscript">

Sub Submit1_onclick
' Problem: window.close() führt vom Dialog zu neuem IE-Fesnter mit
gleichem Inhalt aber Menuzeile etc.
window.returnValue = "say hello from dialog"
window.alert("onclick returns '" & window.returnValue & "'")
window.close()
End Sub

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
A pure HTML-page with HTML-controls only<br />
<input id="Text1" type="text"/><input id="Submit1" type="submit"
value="submit"/>
</div>
</form>
</body>
</html>
 
C

Curious Trigger

Hi,

it seems that I found a solution: in the form which is opened as modal
dialog you have to add a <base target="_self" />-tag to the <head> section
as shown in the following example:

<head runat="server">
<!-- <base href="_self" /> -->
<base target="_self"/>
....
</head>

I read in another newsgroup, that until ASP.NET 1.1 you could achive the
same result with the tag <base href="_self" />. I didn't check this, but
this solution does not work any longer with ASP.NET 2.0. Therefore you have
to use the target-attribute.

Hope this helps anyone with a similar problem.

Curious Trigger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top