[SOLVED] ASP.NET Wizard control, how to add a step dynamically?



public partial class WebForm1 : System.Web.UI.Page
    protected override void OnInit(EventArgs e)
        var t = new TemplatedWizardStep { Title = "Lalalal" };
        t.Controls.Add(new Step1UserControl());

Page markup:

<asp:Wizard runat="server" id="_WizardWebControl">

Step1UserControl.ascx markup:

    <legend>General Informations</legend>
     <p>TEST DYNAMIC</p>    

The step show at the left bar with the Title, but the HTML (fieldset and the paragraph) is not displayed in the step. It requires to be a TemplatedWizardStep too because we use Template for the layout. How do I add a Step dynamically?


I’m not sure that this way is the best practice, but it works:

Step1UserControl should implement ITemplate interface,

public void InstantiateIn(Control container)

and then onInit may look like this:

protected override void OnInit(EventArgs e)
    TemplatedWizardStep templatedWizardStep =  new TemplatedWizardStep { Title = "Lalalal" };

    //  load control by path to initialize markup
    ITemplate control = (ITemplate)Page.LoadControl("\\Step1UserControl.ascx");                        
    templatedWizardStep.ContentTemplate = control;            
    //  make it visible

Answered By – ika

Answer Checked By – Clifford M. (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *