子窗口返回数据给父窗口
我在vs2008中,父页面1.aspx上有一个按钮,点击按钮打开子窗口2.aspx。父窗口中是用showmodaldialog打开子页面,父页面代码如下:protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>var resault=window.showModalDialog('2.aspx',,'dialogWidth=750px,dialogHeight=500px');if (ret != null){ window.document.getElementById('textbox1').value = ret[0];}return false;</script>");
}
子页面上又gridview,单击gridview的某行就返回第一列的值到父页面的textbox1中,并关闭子页面,代码如下:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//鼠标单击事件
if (e.Row.RowType == DataControlRowType.DataRow)
{
Response.Write("javascript:var ret = new Array(1);ret[0] = "+e.Row.Cells[0].Text.ToString()+"; window.returnValue = ret;window.close();return false;");
}
}
不知道代码哪里写错了,望高手指点下 --------------------编程问答-------------------- 你也可以在子窗口直接调用父窗口的js的。
--------------------编程问答--------------------
if(window.opener != null && colvalue[i] != "")
//父窗口js,直接调用修改父窗口
window.opener.SetColValue(colvalue[i],SelectTab.cells(Source).outerText,Style);
if(window.opener != null)
window.opener.focus();
window.close();
我现在是自己写的这段代码没有出现效果 --------------------编程问答-------------------- 回去可以看下! --------------------编程问答-------------------- 先判断一下返回对象是不是空的?然后在进行传值了 --------------------编程问答-------------------- js里面不是有window.history.back(-1); --------------------编程问答--------------------
<script language='javascript'>var resault=window.showModalDialog('2.aspx',,'dialogWidth=750px,dialogHeight=500px');if (ret != null){ window.document.getElementById('textbox1').value = ret[0];}return false;</script>
你定义的变量 resault (单词错了),使用的变量 ret ,这样当然取不到值~~! --------------------编程问答-------------------- 小问题,怕是没有注意到吧 --------------------编程问答--------------------
我把那个变量改回来了,可是点击按钮子页面都没有跳出来
补充:.NET技术 , C#