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

Discussion in 'ASP .Net' started by Curious Trigger, Sep 22, 2006.

  1. 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>
     
    Curious Trigger, Sep 22, 2006
    #1
    1. Advertising

  2. 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

    "Curious Trigger" <> schrieb im Newsbeitrag
    news:%...
    > 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>
    >
    >
     
    Curious Trigger, Sep 24, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Storr
    Replies:
    5
    Views:
    39,745
  2. kurt sune
    Replies:
    2
    Views:
    7,495
    imransyed63
    Aug 19, 2008
  3. Gilles T.
    Replies:
    1
    Views:
    182
    Jim Ley
    Jan 18, 2004
  4. Jonathan
    Replies:
    0
    Views:
    204
    Jonathan
    Jul 19, 2004
  5. Replies:
    0
    Views:
    247
Loading...

Share This Page