【问题标题】:Call button click event from one web form to another将按钮单击事件从一个 Web 表单调用到另一个
【发布时间】:2015-02-24 11:23:35
【问题描述】:

我正在开发一个包含多个 Web 表单的 Web 应用程序。 我需要的是:-我的一个网络表单包含 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
}

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

【问题讨论】:

    标签: c# asp.net button web-applications


    【解决方案1】:

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

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

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

    您必须更改“父窗口按钮的选择器”,以使 jquery 选择器能够唯一地选择父窗体的按钮。

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

    【讨论】:

      【解决方案2】:

      添加这一行:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-23
        • 2011-04-03
        • 1970-01-01
        • 2016-12-25
        • 2015-03-25
        • 1970-01-01
        相关资源
        最近更新 更多