---
title: Connecting web parts with the page wizard
related:
  - https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/displaying-data-advanced-scenarios/creating-wizards-on-websites.md
  - https://docs.kentico.com/k10/custom-development/developing-web-parts/customizing-web-parts.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

The [Page wizard](https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/displaying-data-advanced-scenarios/creating-wizards-on-websites.md) is a set of web parts that allow you to guide users through a sequence of steps on the website. The wizard uses standard pages to define the content of steps. You can extend the logic of the wizard by [customizing the code](https://docs.kentico.com/k10/custom-development/developing-web-parts/customizing-web-parts.md) of the web parts placed onto the wizard steps, for example:

- Define validation rules for web parts — conditions that must be fulfilled before users can move forward from steps containing the web part
- Perform custom actions when moving between steps

To interact with the page wizard from the code of your web parts, override the methods listed below. The methods handle events that occur during the life cycle of each wizard step:

| Wizard step event | Description                                                                                                                                                                                                                                                                                                                                                                     |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| LoadStep          | Occurs when a user opens the step containing the web part.                                                                                                                                                                                                                                                                                                                      |
| StepLoaded        | Occurs after all web parts inside the given step's content have finished the _LoadStep_ event.                                                                                                                                                                                                                                                                                  |
| ValidateStepData  | Allows you to define step validation requirements for the web part. The event occurs when:<br>a user moves to the **next** step by clicking the _Page wizard button_<br>the _Page wizard step action_ web part automatically skips the step (if validation is enabled)<br>**Note**: Moving between steps via the _Page wizard navigation_ web part does not trigger validation. |
| SaveStepData      | Occurs when moving to the next step after the validation is complete.                                                                                                                                                                                                                                                                                                           |
| StepFinished      | Occurs after all web parts in the given step's content have finished the _SaveStepData_ event.                                                                                                                                                                                                                                                                                  |

> **Info:** The base handlers are defined in the **CMSAbstractWebPart** class, so you can override the page wizard event handlers in the code of any web part.

All of the event handlers provide the **StepEventArgs** parameter, which allows you to access the data of the current page wizard step.

#### Cancelling step transitions

You can interrupt transitions to the next wizard step based on custom conditions. Set the **CancelEvent** property of the _StepEventArgs_ parameter during the _ValidateStepData_, _SaveStepData_ or _StepFinished_ events.

For example, add a custom validation condition into the _ValidateStepData_ handler, and set the _CancelEvent_ property to true if the validation fails.

```csharp

e.CancelEvent = true;

```

#### Skipping steps

If you need to completely skip a page wizard step under certain conditions, set the **Skip** property of the _StepEventArgs_ parameter to true in the _LoadStep_ or _StepLoaded_ handler.

```csharp

e.Skip = true;

```

## Example - Creating a form for wizard steps

The following example demonstrates how to create a customized version of the **On-line form** web part for use inside page wizard steps. The custom form:

- Integrates validation of the form's data into the validation of the wizard step
- Saves the form's data when the wizard moves to the next step

See also: [Forms](https://docs.kentico.com/k10/managing-website-content/forms.md)

### Cloning the form web part

1. Open the **Web parts** application.
2. Select the **Forms -> On-line form** web part in the tree.
3. Click **Clone web part** () and enter the following values:

   - **New object display name**: Wizard form
   - **New object code name**: WizardForm
   - **Clone web part to category**: Forms
   - **Clone web part files**: yes (checked)
   - **Cloned web part file name**: BizForms/WizardForm.ascx
4. Click **Clone**.

The system creates a copy of the existing web part and its code files (ASCX and CS) using the specified names.

### Modifying the web part code

1. Open your web project in Visual Studio.
2. Edit the code behind of the cloned web part: **\~/CMSWebParts/BizForms/WizardForm.ascx.cs**

   > **Note:** **Important**
   >
   > If you installed Kentico as a web application, the clone's code files will not be visible right away, since they are not included in the project. In this case:
   >
   > 1. Click **Show all files** at the top of the Solution Explorer.
   > 2. Right-click the **WizardForm.ascx** file in the BizForms folder.
   > 3. Click **Include in Project**.
3. Add the following code into the **SetupControl** method (in the _else_ branch where _StopProcessing_ is false):

   ```csharp

   // Hides the form's default submit button
   viewBiz.SubmitButton.Visible = false;

   ```
4. Add the following overrides for the **ValidateStepData** and **SaveStepData** handlers of page wizard events:

   ```csharp

   protected override void ValidateStepData(object sender, CMS.Base.Web.UI.StepEventArgs e)
   {
       base.ValidateStepData(sender, e);

       // Checks whether the form's data is valid
       if (!viewBiz.ValidateData())
       {
           // Stops the wizard from moving to the next step if the form data is invalid
           e.CancelEvent = true;
       }
   }

   protected override void SaveStepData(object sender, CMS.Base.Web.UI.StepEventArgs e)
   {
       base.SaveStepData(sender, e);

       // Saves the data of the form (replaces the form's submit button)
       if (!viewBiz.SaveData(null))
       {
           // Stops the wizard from moving to the next step if the form's data wasn't saved successfully
           e.CancelEvent = true;
       }
   }

   ```

   > **Tip:** **Tip**: The sample code is only a demonstration of the available event handlers. You do not need to implement the **ValidateStepData** handler for forms in real world scenarios. The **viewBiz.SaveData** method called in the **SaveStepData** handler includes validation (returns a false value if the form's data is invalid).
5. Save the file.

You can now add the customized form web part into the content of page wizard steps. When moving to the next step, the wizard:

1. Validates the form data (according to the settings of the form's fields)
2. Creates a new [data record](https://docs.kentico.com/k10/managing-website-content/forms/managing-form-data.md) for the given form (if the form data is valid)

## Resetting the page wizard

The page wizard tracks which steps individual users have passed through (the system stores the information in the HTTP session). If the **Restrict step order** property of the **Page wizard manager** web part is enabled, the wizard forces users to move through the steps in sequence:

- Users can only move forward through the wizard's steps using the **Next** button
- The **Page wizard navigation** web part displays unvisited steps as inactive items (without links)
- If a user attempts to access an unvisited step through the URL of the step page, the wizard opens the last visited step instead

You can use the API to reset the wizard from the code of any web part placed onto a step. Access the **DocumentWizardManager** property (inherited by all web parts from **CMSAbstractWebPart**) and call the **ResetWizard** method:

```csharp

DocumentWizardManager.ResetWizard();

```

When executed, the method clears the history of visited steps for the user viewing the page.

> **Info:** **Note**: The wizard automatically resets when users click the **Next** button on the last step (if the **Final step URL** property is filled for the **Page wizard manager** web part).
