Wednesday, 10 March 2010

Referencing ASP.NET Wizard Buttons

Technorati Tags: ,

When you use the StepType of Finish a Finish Button is automatically generated and its ID is “FinishButton”, e.g. the WizardStep looks like this:

<asp:WizardStep ID="ConfirmWizardStep" runat="server" Title="Confirm" StepType="Finish">

Due to a business rule you may wish to disable the Finish button and to do this you would think that a FindControl on the WizardStep would work but it doesn’t as the Button is nested below many other tables/templates etc.

The method I used involved a custom recursive FindControl function as follows:

Dim finishButton As Button = CType(FindControlRecursive(WizardControl, "FinishButton"), Button)

Public Shared Function FindControlRecursive(ByVal root As Control, ByVal id As String) As Control

If root.ID = id Then
End If
c As Control
For Each c In root.Controls
Dim t As Control = FindControlRecursive(c, id)
If Not t Is Nothing Then
End If
Return Nothing


No comments: