?
Solved

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

Posted on 2008-10-24
3
Medium Priority
?
1,096 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
ororiole earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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