Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

returnValue is null after calling window.ShowModalDialog(....)

I have an Asp.net project. One aspx page displays another as a modal dialog box. The return value is being passed back as "null" and I don't know why? Also alert(returnValue); will display the value as null. Can someone help me figure out why? Attached is the zip file for the project. Or the code markup and CS is included inline below.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" 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">

<script language="javascript" type="text/javascript">
function ShowPopup()
{
    var returnValue = window.showModalDialog('ModalPopup.aspx', 'dialogHeight:100px;dialogWidth:280px;status:no');
    alert(returnValue);
}
</script>
<title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Button ID="Button1" runat="server" Text="Show Popup"
            OnClientClick="javascript:ShowPopup()" />  
    </div>

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

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

-----------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalPopup.aspx.cs" Inherits="ModalPopup" %>

<!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">
<base target=_self>
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
        Text="Close Popup" />
    </form>
</body>
</html>

=====================C# code for ModalPopup.aspx
/* Modal Popup.aspx */
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ModalPopup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script language='javascript'> {window.ReturnValue='hello';self.close();}</script>");
    }
}
Avatar of krishna kishore mellacheruvu venkata
krishna kishore mellacheruvu venkata
Flag of India image

is modelpopup.aspx is in the same folder as the asp.net page. other wise it gives error.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet

ASKER

Thank you. I could just slap myself for that one.