For some reason, the value returned by the Modal Dialog box is always “undefined”.
My Main page (aspx):
<%@ Page Title="Home Page" Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html>
<head></head>
<body>
<script type="text/javascript">
function openWindows () {
var getval;
getval = window.showModalDialog('../WebSite/popups/uploader.htm');
document.getElementById("Input").value = getval;
}
</script>
<input id="Input" runat="server" />
<input type="button" id="Button1" runat="server" onclick="openWindows()" value="Choose Image"/>
</form>
</body>
</html>
So in this case, the value of getval is always “undefined”
My Dialog Box (HTML) Code:
<html>
<head>
<script type="text/javascript">
function ReturnValues() {
var objfile = document.getElementById("fileup").value
document.getElementById("TxtInput").value = objfile
var vReturnValue = document.getElementById("TxtInput").value;
window.ReturnValue = vReturnValue;
window.close();
}
</script>
</head>
<body>
<form id="Formuploader" method="post" runat="server">
<input id="TxtInput" type="hidden" runat="server" /><br />
<button id="btnSaveImage" runat="server" onclick="ReturnValues()">Save Image</button>
</form>
</body>
</html>
Here, ReturnValue does have the required value. But as soon as the ModalDialog closes, the getval variable in the main window becomes undefined.
Any help is greatly appreciated.
Thanks!
when you return value, do it this way:
use lowercase
returnValue, notReturnValue.also, your modal dialog is not closing. to fix that, change your button to a link.