Solved

How to invoke Wizard.MoveTo() on .aspx page from .ascx user control?

Posted on 2008-10-24
3
1,030 Views
Last Modified: 2009-02-08
My main page is store.aspx, which contains an <asp:Wizard> control.

Each of the WizardSteps are separate ASCX controls:

<asp:WizardStep ID="AccessoriesWizardStep" runat="server" StepType="Step" Title="Store">
<storewizard:StoreProducts ID="StoreProducts" runat="server" />
</asp:WizardStep>

<asp:WizardStep ID="PaymentDetailsWizardStep" runat="server" StepType="Step" Title="Payment Information">
<storewizard:StorePayment ID="StorePayment" runat="server" />
/asp:WizardStep>

Both of these controls then contain a reference to a common "Shopping Cart" control, which shows products added to the cart, price, and a Checkout button.  Everything is working great, except for the Checkout button.

Here is the problem: I am not able to get the Checkout button to fire off the OnNextButtonClick event contained in the parent Store.aspx page.  This OnNextButtonClick event references the .MoveTo method.

How do I accomplish this task?

Thank you.

David


                                    
0
Comment
Question by:axiomllc
3 Comments
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 22805386
I think you are making this a little harder than it needs to be. The wizard provides you with buttons, you could set the text of NextButton to "Checkout" and use it. Hide the button of the usercontrol. That's the simplest.

However, since you want to use a user control, no problem there. First a note about events: A Button is a class, and any event defined inside a class can only be fired from inside that class. So any event inside the Wizard control, in your case the OnNextButtonClick event, cannot be fired from a Button class, or any other class, except the Wizard.

However, any number of classes may subscribe to an event, by registering an EventHandler delegate to the event. So you want to register an EventHandler on your page, with the Button onClick event of the usercontrol. Maybe its called Nextbutton_Click(object, EventArgs). This is your EventHandler that contains the .Moveto() method.

You need to expose the onclick event of the usercontrol button thru a property, using the little known C# reserved words "add" and "remove". We'll call the event property ButtonClick. In the userControl tag, this will automatically create an event attribute called OnButtonClick. Your code will look something like this:
//the usercontrol: 

  public partial class StorePayment : System.Web.UI.UserControl

    {

        //you must mark the property with the "event" keyword and a type of EventHandler

        public event EventHandler ButtonClick //<--We call it ButtonClick

        {

            add { MyButton.Click += value; } //this is the button in the UserControl

            remove { MyButton.Click -= value; }

        }

        protected void Page_Load(object sender, EventArgs e)

        {
 

        }

    }
 

//in your page codebehind:

        protected void Nextbutton_Click(object sender, EventArgs e)

        {

            Wizard1.MoveTo(WizardStep3);

            TextBox1.Text = "finished.";

        }
 

//in your page markup now you can reference OnButtonClick in the userControl:

                <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">

                    <uc:StorePayment ID="StorePayment1" runat="server"  OnButtonClick="Nextbutton_Click"/>

                </asp:WizardStep>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now