August 20, 2007

HOWTO: Find Controls In Wizard Navigation Steps

If you use ASP.NET's Wizard control, chances are that you've needed to get ahold of one or more of the controls in the navigation area using FindControl() but have been unable to.

The reason is that when ASP.NET adds the navigation area controls to the wizard control, it adds a prefix onto the control name.

To find the control, add the appropriate prefix to the control name:
If your control is in...Use...
StartNavigationTemplateStartNavigationTemplateContainerID$
StepNavigationTemplateStepNavigationTemplateContainerID$
FinishNavigationTemplateFinishNavigationTemplateContainerID$

For example, if you want to find a button named "FinishButton" in the finish navigation step, you'd use a line of code like this...

Button finishButton = Wizard1.FindControl("FinishNavigationTemplateContainerID$FinishButton") as Button;

At this point, you'll be able to use all of the normal properties of the button, like this snippet to disable the finish button after it has been clicked:

string script = String.Format("window.setTimeout(function(){{{0}.disabled = true;}},10);", finishButton.ClientID);
finishButton.OnClientClick = script;

5 comments:

Philip Stratford said...

Very useful, thanks for sharing!

Kimberlito said...

After some days trying to find a solution do hide the finish button in a wizard control, I've found it here. Thank you.

Shakirudeen Lasisi said...

Awesome Man, Thanx a lot

Ephemera said...

Exactly what I was looking for! Thank for saving me time trying to figure this out.

Arun Raut said...

Awesome Man .. Thanks Alot ..