从一个 Web 表单调用按钮单击事件到另一个 Web 表单

Call button click event from one web form to another

我正在开发一个网络 application.which 包含多个网络表单。 我需要的是:-我的一个网络表单包含带有关闭按钮的 IFrame(它将打开另一个带有少量文本框和按钮控件的 aspx 页面)。

    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
}

谁能帮我解决这个问题提前谢谢。

添加这一行:

ScriptManager.RegisterStartupScript(this, typeof(string), "script", " parent.location.href = parent.location.href;", false);

在此之后或代替此 //在此之后我想调用那个父表单 BTNCClose_Click

在会话对象中存储值后,它将刷新父页面并更新值。

这是您可以处理的一种方式

在子窗体的BTNCCloseChild_Click事件中,在末尾添加如下代码

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

您必须更改 'the selector of your parent window button',以适应 jquery select 或唯一 select 父表单的按钮。

如果有嵌套的 iframe,您可能必须使用 window.top 而不是 window.parent