Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Wizard layout template programmatically

Tags:

asp.net

wizard

I am creating a wizard control from the codebehind based on some conditions from the database. I need to apply the layout template from the code. I checked MS example, its all based on the design time, not at runtime.

Please help me in seting the layout template for asp.net wizard control. Preferably some code examples.

Update:

I think I should have been little more elaborate. Actually I am not seeing the controls in the wizard that i have added from the template. Here is my sample code

public class WizardTemplate:ITemplate
{
    public void InstantiateIn(Control container)
    {
        PlaceHolder header = new PlaceHolder();
        header.Controls.Add(new LiteralControl("I am from Header"));
        header.ID = Wizard.HeaderPlaceholderId;

        PlaceHolder displaySideBar = new PlaceHolder();
        displaySideBar.Controls.Add(new LiteralControl("I am from displaySideBar"));
        displaySideBar.ID = Wizard.SideBarPlaceholderId;

        PlaceHolder wizardStep = new PlaceHolder();
        wizardStep.Controls.Add(new LiteralControl("I am from wizard step"));
        wizardStep.ID = Wizard.WizardStepPlaceholderId;

        PlaceHolder navigation = new PlaceHolder();
        navigation.ID = Wizard.NavigationPlaceholderId;

        container.Controls.Add(header);
        container.Controls.Add(displaySideBar);
        container.Controls.Add(wizardStep);

        container.Controls.Add(navigation);
    }
}

I am doing this on page init. I dont see the controls I have created in it. Wondering whats going wrong here.

Wizard testWizard = new Wizard();
        testWizard.LayoutTemplate = new WizardTemplate();
        for (int i = 0; i < 4; i++)
        {
            WizardStep step = new WizardStep();
            step.Title = "Step" + i.ToString();
            step.ID = "Step" + i.ToString();
            step.Controls.Add(new LiteralControl("<b> Step" + i.ToString() + "</b>"));
            testWizard.WizardSteps.Add(step);

        }
        pnlRunTimeWizardContainer.Controls.Add(testWizard);

Eventually I would want the wizard to use the below layout but in code

<asp:Wizard ID="Wizard1" runat="server" EnableViewState="true">
        <LayoutTemplate>
            <div>
                <asp:PlaceHolder ID="headerPlaceHolder" runat="server" />
            </div>
            <div style="float: right">
                <asp:PlaceHolder ID="navigationPlaceHolder" runat="server" />
            </div>
            <div>
                <asp:PlaceHolder ID="sideBarPlaceHolder" runat="server" />
            </div>
            <div>
                <asp:PlaceHolder ID="WizardStepPlaceHolder" runat="server" />
            </div>
        </LayoutTemplate>
        <WizardSteps>
        </WizardSteps>
    </asp:Wizard>
like image 646
Ahuman Avatar asked Sep 17 '26 04:09

Ahuman


1 Answers

Here you go:

public class WizardLayoutTemplate : ITemplate
{
  public void InstantiateIn(Control container)
  {
    // do some cool stuff here with the container control
  }
}

myWizard.LayoutTemplate = new WizardLayoutTemplate();
like image 131
Bazzz Avatar answered Sep 18 '26 16:09

Bazzz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!