1

I have a ASP.NET Page that contains a Shopping Cart UserControl. Now, when user Click on CheckoutButton which is in UserControl i want to redirect him to a page where customer information will be entered when CustomerID session is null. enter image description here

In UserControl:

protected void lnkCheckOut_Click1(object sender, EventArgs e)
    {

        if (Session["SalesCustomerID"] != null)
        {

            //CompleteOrder();

        }
        else
        {
            //Call here method of Parent Page 
        }
    }

In Product.aspx.cs

In Product.aspx page the UserControl exists. this page also contains the MasterPage.

 public void CallCustomerForm()
    {
      //show/redirect to customer entry form
    }

So, how to call a method which is in ParentControl from UserControl button click in asp.net using c#?

SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143
  • 1
    Any reason to not create an Event on the user control that the page can subscribe to, and keep the page-specific redirect code in the page? http://stackoverflow.com/questions/6192739/how-do-i-raise-an-event-in-a-usercontrol-and-catch-it-in-mainpage – Malk Mar 04 '14 at 07:03

1 Answers1

2

I think you ought to stop and think about your design. Your controls should not ever need to know anything about the page that contains them - the fact that you need to go find a control on the page from within another control tells me that you ought to rethink the problem.

The best thing I can tell you (with what little I know of your architecture) is that you ought to pass in a reference to the control you hope to find into your user control. This way your control does not have to know about things outside itself.

Similar Questions have already been answered before.

Here: http://www.codeproject.com/Articles/28503/Transfering-control-to-Page-ASPX-from-Control-ASCX

Here: How to call a method from user control to aspx page?

And Lastly, Here: ASP.NET Calling a Method in (ASPX) From a UserControl (ASCX)?

Community
  • 1
  • 1
Josh
  • 253
  • 3
  • 11