從打開的新窗口中傳值到其父窗口.
1.單個值
Response.Write("<script> if(opener!=undefined) {opener.document.all['" + Request.QueryString["txtID"] + "'].value = '" + strApproved.Trim() + "';}</script>");
其中 : opener 就是指打開此窗口的父窗口. Request.QueryString["txtID"] 爲這個窗口的某一個控件的ID, strApproved.Trim() 爲被打開窗口中的一個字符串.
2. 多個值的話, 用Session傳值
先在子窗口定義Session[“dtValue”]=dt; //dt爲子窗口生成的結果.
返回按鈕中:
Response.Write("<script>opener.location.href=opener.location.href;window.close('Search.aspx');</script>");
再在父頁面的Page_Load()中:
if (Session["dtSearch"]!=null)
{
DataTable dtGetValue=((DataTable)Session["dtSearch"]);
Session["dtSearch"]=null;
}