Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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