Solved

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

Posted on 2008-10-24
3
1,077 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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