父页面
- HTML code
<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" />
子页面 用gridview绑定的数据
- C# code
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();"); } }
传值时发生错误。。。。
------解决方案--------------------------------------------------------
window.dialogArguments.document.getElementById('txtpunit').value好像没看到有人这么用过,window.dialogArguments传过来的一般是变量或者变量数组,
看你子页面代码是想单击gridview行向父页面textbox传值?如果是这样的话,请先试试用:
top.document.getElementById('txtpunit').value或者parent.document.getElementById('txtpunit').value看能否实现
------解决方案--------------------------------------------------------
你第二个参数传的是字符串"window"。可以试一试window或者this。不确认是不是能用在这里
例子代码:
父窗口:
- HTML code
<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>