Solved

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

Posted on 2008-10-24
3
1,016 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

20 Experts available now in Live!

Get 1:1 Help Now