日期:2014-05-17  浏览次数:20525 次

求助:有关JS父页和子页问题
父页代码:
HTML code

<script type="text/javascript"  >
        function manage() {
            var hdc = window.open("detail.aspx", "NewWindow", "height=200, width=400, top=400,left=900 toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
        }
    </script>
<asp:TextBox ID="txtpunit" class="text-input small-input" runat="server" ></asp:TextBox>
<img alt="detail" src="Images/png/link.png" onclick="manage()"  height="16px" width="16px" />



子夜代码:用的gridview,取一个单元格的值,传给父页

C# code


 string name = e.Row.Cells[1].Text.Trim();
 e.Row.Attributes.Add("onclick ", " window.opener.document.getElementById('txtpunit').value="+name+ ";window.opener=null;window.close();");




取值这些没问题,就是从子页传不到父页去,TextBox里面取不了值。。该如何解决?

------解决方案--------------------
e.Row.Attributes.Add("onclick ", " window.opener.document.getElementById('txtpunit').value='"+name+ "';window.opener=null;window.close();");
非数字要加引号。

另外window.opener只能用在window.open打开的子页面中,