window.showModalDialog子页面向父页面传值
父页面
<script type="text/javascript" > function manage() { var hdc = window.showModalDialog("detail.aspx", "window", "resizable:no;scroll:no;status:no;dialogLeft=900px;dialogTop=400px;dialogWidth=315px;dialogHeight=188px;center=no;help=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" />
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string name = e.Row.Cells[0].Text.Trim(); e.Row.Attributes.Add("onclick ", " window.dialogArguments.document.getElementById('txtpunit').value='" + name + "';window.close();"); } }
<HTML><input type=button value="CustomConfirm" onclick="ShowMyDialog()"><script language="javascript">function ShowMyDialog(){ var obj = new Object(); obj.data1 = 'some data 1'; obj.data2 = 'some data 2'; showModalDialog('Child.htm', obj, ''); alert(obj.returnvalue);}</script></HTML>
[解决办法]
子页面:
e.Row.Attributes.Add("onclick ", " window.returnValue='" + name + "';window.close();");
父页面:
<script type="text/javascript" >
function manage() {
var hdc = window.showModalDialog("detail.aspx", "window", "resizable:no;scroll:no;status:no;dialogLeft=900px;dialogTop=400px;dialogWidth=315px;dialogHeight=188px;center=no;help=no");
document.getElementById('txtpunit').value=hdc;
}
</script>