views:

12

answers:

2

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

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

Why is that?

A: 

Did you try this:

Literal literal = MyWizard.FindControl("MyLiteral") as Literal;
if (literal != null)
    // do something with literal

(Maybe you tried but how can I know that from your question?)

Slauma
I tried, but I used: this.FindControl as I need this on every wizard step.
Blankman
+1  A: 

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.

dave thieben