How to Trigger Click Event of a Button in UserControl from ContentPage?

为君一笑 提交于 2019-12-11 21:21:25

问题


I have a ShoppingCart UserControl on MasterPage. I have a following functionality: User adds item to the cart. after clicking the button "Complete Sale" in UserControl the page is redirected to "CustomerInfo.aspx" and after filling the Customer information and clicking on submit which is on CustomerInfo.aspx page i want to call the "Complete Sale" click event of UserControl from "Customerinfo.aspx" page.

Customerinfo.aspx.cs

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            bool val=false;
            int retVal = 0;
            CustomerBiz objCust = new CustomerBiz();

            objCust.FirstName = txtFirstName.Text.Trim();
            objCust.LastName = txtLastName.Text.Trim();
            objCust.Phone = txtPhone.Text.Trim();
            objCust.Email = txtEmail.Text.Trim();
            if (hdnCustomerID!=null && !string.IsNullOrEmpty(hdnCustomerID.Value) && hdnCustomerID.Value!="0")
                objCust.CustomerID = Convert.ToInt32(hdnCustomerID.Value);
            else
                objCust.CustomerID =0;
            retVal = objCust.AddCustomerInfo();
            if (retVal > 0)
            {
                //success     
                UserControl uch = Page.Master.FindControl("shpCart") as UserControl;
                Button lnkCheckOut=uch.FindControl("lnkCheckOut") as Button;
                lnkCheckOut.Text = "Found in Customer.aspx";
                //lnkCheckOut.Click += new EventHandler(lnkCheckOut.);
                lnkCheckOut.Text = "You Clicked";//Here Text of button in UserControl changes but how to call the ClickEvent of this button in Customerinfo.aspx page ?

                // completeBtn.Click += new EventHandler(btnSubmit_Click);
                Response.Redirect("Devices.aspx", true);
            }
            else
            { 
                //fail
            }
       }
        catch (Exception ex)
        {

        }
    }

Here the Button text changes in UserControl. But i am not able to call the Click event of this button from CustomerInfo.aspx (ContentPage) any suggestions?

来源:https://stackoverflow.com/questions/23283922/how-to-trigger-click-event-of-a-button-in-usercontrol-from-contentpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!