Simply placing the SideBarButton inside a Panel, will enable you to set the visibility property of the Panel, which, in turn allows shows or hides the button.
However, when a SideBar LinkButton is hidden it will still leave gaps if the Contaner DataList is set to Table RepeatLayout or Vertical RepeatDirection. Ensure, that RepeatLayout is set to Flow AND RepeatDirection is set to Horizontal.
The following sample demonstrates how to hide/show SideBarButtons in the SideBarTemplate.
ASPX (SideBarTemplate code within the Wizard)
<SideBarTemplate>
<asp:DataList ID="SideBarList" CellSpacing="0" runat="server" OnItemDataBound="SideBarList_ItemDataBound" RepeatLayout="Flow" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:Panel style="padding:2px;" ID="pnlSideBarLink" runat="server"><asp:LinkButton ID="SideBarButton" ForeColor="White" runat="server"></asp:LinkButton></asp:Panel>
</ItemTemplate>
<SelectedItemStyle Font-Bold="true"/>
</asp:DataList>
</SideBarTemplate>
ASPX.VB (Code Behind):
Public Sub SideBarList_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
Dim dataitem As WizardStep = CType(e.Item.DataItem, WizardStep)
Dim lnkBtn As LinkButton = CType(e.Item.FindControl("SideBarButton"), LinkButton)
If Not dataitem Is Nothing Then
' method to show/hide items
ValidateMenuItem(dataitem, e.Item)
' one item should be visible but disabled in certain scenarios
If e.Item.ItemIndex = 5 Then
lnkBtn.Enabled = rblSType.SelectedIndex > 0
End If
End If
End Sub
' method to show/hide items
Private Sub ValidateMenuItem(ByVal wizStep As WizardStep, ByVal dli As DataListItem)
Dim pnlSideBarLink As Panel = CType(dli.FindControl("pnlSideBarLink"), Panel)
Dim b As Boolean = True
Select Case Me.WizardType
Case WizardTypes.Tasks
' if the title matches the step, show/hide steps in menu
If wizStep.Title = step_location.Title Then
b = False
End If
Case WizardTypes.Lists
' if the title matches the step, show/hide steps in menu
Select Case wizStep.Title
Case step_location.Title, step_options.Title, step_reminder.Title, step_sched_type.Title, step_schedule.Title
b = False
End Select
End Select
pnlSideBarLink.Visible = b
End Sub
' Wizard is used for three types of data entry in this example
Public Enum WizardTypes
Tasks
Schedules
Lists
End Enum
Public Property WizardType() As WizardTypes
Get
Dim wt As WizardTypes = WizardTypes.Lists
If Not ViewState("WizardType") Is Nothing Then
wt = ViewState("WizardType")
End If
Return wt
End Get
Set(ByVal value As WizardTypes)
ViewState("WizardType") = value
ReSetType()
End Set
End Property
At this point we have only hidden/shown items in the SideBarMenu. The navigation itself, still needs to be coded. Fortunately, this is much more straightforward. The following demonstrates how to skip a step programatically in the NextButtonClick and PreviousButtonclick Events.
Private Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick
Select Case e.CurrentStepIndex
Case 4
If rblSType.SelectedIndex < 1 Then
Wizard1.ActiveStepIndex = 6
End If
End Select
End Sub
Private Sub Wizard1_PreviousButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.PreviousButtonClick
Select Case e.CurrentStepIndex
Case 6
If rblSType.SelectedIndex < 1 Then
Wizard1.ActiveStepIndex = 4
End If
End Select
End Sub |