Home
 Index > ASP.NET Web Applications > The Visible property of a View control can only...

ASP.NET Web Applications:  Debugging , Wizard , SideBarButton , MultiView

The Visible property of a View control can only be set by setting the active View of a MultiView

The error was thrown when attempting to set a Wizard's SideBarButton's visible property to false or true during it's DataList's ItemDataBound event.

Added on 21 Jul 2008

Scenarios:

Scenario Summary:
The requirement is to show only the step's in a Wizard's SideBar that are appropriate to the current action.
Scenario Details:
A single Wizard is used for various purposes; however, not all of the steps will be used for all purposes.  Therefore, we need to hide the unused steps in the SideBar whenever necessary.  Attempting to modify the SideBarButton's visible property on ItemDataBound throws the following error: The Visible property of a View control can only be set by setting the active View of a MultiView.
Added on 21 Jul 2008

Solution Summary:
It is impossible to modify the button's visible property (even though other properties, such as "Enable" can be set). You can however, place the SideBarButton inside a Panel, and set the Panel's visibility as desired.
Solution Details:

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 ObjectByVal 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 ObjectByVal 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 ObjectByVal 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
Was this solution useful? Yes No Added on 21 Jul 2008
Rating: 

Copyright 2010 © E-Centric, Inc. | Terms of Use