Search code examples
c#asp.netcontrolswizardasp.net-controls

control inside Wizard <StepNavigationTemplate> tag isn't available in code-behind?


I put a Literal control in the tag in the Wizard control.

In the codebehind, I can't access that control.

Why is that?


Solution

  • Any sort of template control (Wizard, Repeater, etc.) doesn't expose the controls inside the template as member variables. You will need to use FindControl on the correct Step.

    i.e.,

    var myStep = wizard.Steps[1]; // or however you want to find it
    var myLiteral = myStep.FindControl("MyLiteral") as Literal;
    

    if you have other templated controls within your wizard Step, you'd need to do a "FindControl" on those as well to continue drilling down to your literal. I created a "FindControlRecursive" extension method to make this easier.