2012-05-19 101 views
1

由於某種原因,模態對話框返回的值始終爲「未定義」。ModalDialog的返回值始終未定義

我的主頁(CSS):

<%@ 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> 

因此,在這種情況下,GETVAL的值始終爲 「不確定」

我的對話框(HTML)代碼:

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

這裏,ReturnValue具有所需的值。但是一旦ModalDialog關閉,主窗口中的getval變量就變得不確定。

任何幫助,非常感謝。 謝謝!

當您返回值

回答

0

,做這種方式:

window.returnValue = vReturnValue; 

使用小寫returnValue,不ReturnValue

此外,您的模式對話框不關閉。要解決這個問題,請將您的按鈕更改爲鏈接。

<a href="#" id="btnSaveImage" runat="server" target="_self" onclick="ReturnValue()"> 
     Save Image</a> 
+0

我不明白這一點。 objfile如何定義? 此外,值正在填充,直到 window.ReturnValue = vReturnValue; –

+0

我更新了我的帖子。另外,請看下面關於如何返回複雜數據的文章。 http://p2p.wrox.com/javascript/26755-return-value-showmodaldialog.html –

+0

我有另一個問題: [link] http://stackoverflow.com/questions/10662592/calling-code-behind-從 - javascript –

0

試試這個:

window.opener.document.getElementById("Input").value = getval; 
+0

沒有..沒有工作:( –

+0

問題在於'window.ReturnValue',它應該是'window.returnValue'。 –