2015-02-24 140 views
0

我正在開發一個Web應用程序,它包含多個Web窗體。 我需要的是:我的網頁表單中的一個包含IFrame(它將打開另一個帶有幾個文本框和按鈕控件的aspx頁面),並帶有關閉按鈕。呼叫按鈕單擊事件從一個Web窗體到另一個

If i click on the button in the child form(Iframe form), once complete its action it should call the close button function of the parent form. 

here is the code. 

父窗體代碼

protected void BTNCClose_Click(object sender, EventArgs e) 
      { 
       MethodToExecute(); 
      } 
      public void MethodToExecute() //call this method 
      { 
       UPCCharges.Update(); 
       if (HttpContext.Current.Session["CCost"] != null) 
       { 
        TxtCCost.Text = Session["CCost"].ToString(); 
       } 
       if (HttpContext.Current.Session["CYeild"] != null) 
       { 
        TxtCYeild.Text = Session["CYeild"].ToString(); 
       } 
       if (HttpContext.Current.Session["CName"] != null) 
       { 
        TxtCName.Text = Session["CName"].ToString(); 
       } 
       if (TxtCName.Text != "" && TxtCYeild.Text != "" && TxtCCost.Text != "") 
       { 
        TxtCrJobId.Text = Session["CJobID"].ToString(); 
        Session.Remove("CCost"); Session.Remove("CYeild"); 
        Session.Remove("CName"); Session.Remove("CJobID"); 

       } 
       Diva.Visible = false; 
       IFMC.Visible = false; 

      } 

,這是子窗體(在iframe中)

protected void BTNCCloseChild_Click(object sender, EventArgs e) 
{     
    for (int vLoop2 = 0; vLoop2 < gvInner.Items.Count; vLoop2++) 
    { 
     if (TxtTotalCFrom1 != null && TxtTotalCFrom2 != null) 
     { 
      TextBox TxtTotalCFrom = (TextBox)gvInner.Items[vLoop2].FindControl("TxtTCFrom"); 
      TextBox TxtTotalCYeild = (TextBox)gvInner.Items[vLoop2].FindControl("TxtTCYeild"); 
      Session["CCost"] = (mobjGenlib.ConvertDecimal(TxtTFrom1.Text) + mobjGenlib.ConvertDecimal(TxtTFrom2.Text)).ToString(); 
      Session["CYeild"] = (mobjGenlib.ConvertDecimal(TxtRO.Text) - mobjGenlib.ConvertDecimal(TxtTFrom.Text)).ToString(); 
      Session["CName"] = gvInner.Items.Count.Items[vLoop2].Cells[1].Text; 
      Session["CJobID"] = gvInner.Items.Count.Items[vLoop2].Cells[2].Text; 
     } 
    } 

//after this i want to call that parent form BTNCClose_Click 
} 

任何一個可以幫助我提前解決這個感謝。

回答

1

這是你可以在BTNCCloseChild_Click事件子窗體的處理

的一種方式,在最後添加如下代碼

string script [email protected]"$('the selector of your parent window button', 
        window.parent.document).click();"; 
Page.ClientScript.RegisterStartupScript(this.GetType(), "CloseParent", script); 

你必須改變「你的父母的選擇窗口按鈕',以appropreate jquery選擇器來唯一選擇父窗體的按鈕。

如果存在嵌套的iframe,則可能必須使用window.top而不是window.parent

+0

謝謝對衝!!!!! – Appdev 2015-02-25 04:46:41

-2

添加此行:

ScriptManager.RegisterStartupScript(此的typeof(字符串), 「腳本」, 「parent.location.href = parent.location.href;」,假);

在此之後或代替該 //在這之後,我想調用父窗體BTNCClose_Click

在會話對象存儲的值將刷新父頁面和值將被更新後。

相關問題