彈出新窗口,填寫數據,提交後,關閉該彈出窗口,刷新父頁面

父窗口彈出子窗口的 button處理事件:
private void Button1_Click(object sender, System.EventArgs e)
  {
   Response.Write("<script language=javascript>window.open('WebForm1.aspx','', 'alwaysRaised=1,dependent=1,resizable=0,scrollbars,width=450,height=550');</script>");
  }
父窗口html代碼添加如下javascript代碼
<script language="javascript" type="text/javascript">function refresh() { this.location = this.location; }</script><script language="javascript" type="text/javascript">function refresh() { this.location = this.location; }</script><script language="javascript" type="text/javascript">function refresh() { this.location = this.location; }</script><script language="javascript">
function refresh()
{
this.location = this.location;
}
</script>
子窗口關閉窗口的 button處理事件:
private void Button1_Click(object sender, System.EventArgs e)
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append("<script language = javascript>");
scriptString.Append("window.opener.refresh();");

scriptString.Append( " window.focus();" );
scriptString.Append( " window.opener=null;" );
scriptString.Append( " window.close(); " );

scriptString.Append("</"+"script>");
Response.Write(scriptString.ToString());

// Response.Write("<script language=javascript>window.close()</script>");
}

 

 

 

現在用asp.net2.0,要實現一個功能:a頁面點擊一個按鈕,彈出一個窗口,選擇數據,然後數據返回到a頁面的某個textbox裏面。
以前我用
if(!IsClientScriptBlockRegistered("clientScript2"))
  {
  string strScript2= "<script>function OpenWin2(){var str=window.showModalDialog('user.aspx',document.Form1.sx.value,'dialogWidth:455px; dialogHeight:450px;');document.Form1.sx.value=str}</script>";
  RegisterClientScriptBlock("clientScript2", strScript2);
  }
  nw.Attributes.Add("onclick", "OpenWin()");
這樣去做,不知道還有其他更好的方法嗎?

用window.open也可以,在彈出窗口中調用父窗口的js函數,實現傳值:opener.someFunction("someValue");

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章