|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn this article, I will explain how to create a tab strip control within ASP.NET 2.0 using existing controls. We all had hoped that with the release of .NET 2.0, Microsoft would incorporate many WebForm controls required for every day use, such as a TabStrip, LoginXXX, etc. They provided us with more controls than we know what to do with, however, there is still no tab strip control within ASP.NET 2.0. But there is good news. With three of the new 2.0 controls ( Instead of building a WebForms page with these controls incorporated into the page, I will build a CompositeControlMicrosoft MSDN: "A I think you can tell where I am headed… I am going to build a composite control that contains an embedded I not going to examine the Building the CompositeControl – TabularMultiViewNow that you have a thorough understanding of the basic functionality of each control, I will use them as follows to mimic a tabstrip. The The base functionality provided by the
Public Class TabularView
Inherits View
Public Property TabName as String
...
End Property
Public Property Selectable as Boolean
...
End Property
Public Property ToolTip as String
...
End Property
...
End Class
Now to the Real CodeThe composite control will be named Public Class TabularMultiView
Inherits CompositeControl
End Class
Without going into too much detail about the Protected Sub CreateChildControls()
…
Dim menu as
new Menu
Dim mltView as new MultiView
Me.Controls.Add(menu)
Me.Controls.Add(mltView)
…
End Sub
Note: The code above does not produce anything meaningful. Now I needed a way to embed each tab's content within this new This is accomplished with the following: DefaultProperty("Views"), _
ParseChildren(True, "Views")> _
Public Class TabularMultiView
Inherits CompositeControl
private _List as List(Of TabularView)
<Category("Behavior"), _
Description("The TabularView collection"), _
DesignerSerializationVisibility _
(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
Public ReadOnly Property Views() As List(Of TabularView)
Get
If _List Is Nothing Then
_List = New List(Of TabularView)
End If
Return _List
End Get
End Property
…
End Class
As you can see, the <cc:TabularMultiView ID="tabMltView" runat="server">
<cc:TabularView ID="TabularView1" runat="server"
TabName="TabName1">
Content Here…
</cc:TabularView>
<cc:TabularView ID="TabularView2" runat="server"
TabName="TabName2">
Content Here…
</cc:TabularView>
</cc:TabularMultiView>
The For Each tabView As TabularView In Views
InnerMultiView.Views.Add(tabView)
Next
To assign the If InnerMultiView.Views.Count >= 0 AndAlso Me.ActiveIndex _
< InnerMultiView.Views.Count Then
InnerMultiView.ActiveViewIndex = Me.ActiveIndex
End If
Incorporating the Menus - TabsAs you are iterating through the For Each tabView As TabularView In Views
InnerMultiView.Views.Add(tabView)
InnerMenu.Items.Add(new MenuItem(“name”, “value”))
Next
Remember, we added the Dim index as Integer = 0
Dim menuItem as MenuItem
For Each tabView As TabularView In Views
' Views
InnerMultiView.Views.Add(tabView)
' Menu items - tabs
menuItem = new MenuItem(tabView.TabName, index)
menuItem.Selectable = tabView.Selectable
InnerMenu.Items.Add(new menuItem)
index += 1
Next
After initializing the InnerMenu = New Menu()
AddHandler m_Menu.MenuItemClick, AddressOf Menu_MenuItemClick
Within the menu's Protected Sub Menu_MenuItemClick(ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.MenuEventArgs)_
InnerMultiView.ActiveViewIndex = CInt(e.Item.Value)
' Inform the user of item click event
RaiseEvent MenuItemClick(sender, e)
End Sub
Putting it all Together - CreateChildControls() MethodProtected Overrides Sub CreateChildControls()
InnerMenu = New Menu()
' Capture Menu Item click event, and change
' the ActiveIndex on the MultiView
AddHandler m_Menu.MenuItemClick, AddressOf Menu_MenuItemClick
InnerMenu.ID = "tigerMenu"
InnerMenu.Orientation = Orientation.Horizontal
InnerMenu.CssClass = Me.TabularMenuCSS
' Static Menu Item Style
If String.IsNullOrEmpty(Me.TabularMenuItemCSS) Then
InnerMenu.StaticMenuItemStyle.BackColor = Color.DarkGray
InnerMenu.StaticMenuItemStyle.ForeColor = Color.White
Else
InnerMenu.StaticMenuItemStyle.CssClass = Me.TabularMenuItemCSS
InnerMenu.StaticMenuItemStyle.HorizontalPadding = 0
InnerMenu.StaticMenuItemStyle.VerticalPadding = 0
End If
' Static Selected Style
If String.IsNullOrEmpty(Me.TabularMenuItemCSS) Then
InnerMenu.StaticSelectedStyle.BackColor = Color.LightGray
InnerMenu.StaticSelectedStyle.ForeColor = Color.White
Else
InnerMenu.StaticSelectedStyle.CssClass = _
Me.TabularMenuSelectedItemCSS
InnerMenu.StaticSelectedStyle.HorizontalPadding = 0
InnerMenu.StaticSelectedStyle.VerticalPadding = 0
End If
Dim index As Integer = 0
Dim mItem As MenuItem
For Each tabView As TabularView In Views
mItem = New MenuItem(IIf(String.IsNullOrEmpty(tabView.TabName), _
SetTabTextWidth(tabView.ID), _
SetTabTextWidth(tabView.TabName)), _
index.ToString())
mItem.Selected = IIf(ActiveIndex.Equals(index), True, False)
mItem.Selectable = IIf(tabView.Selectable, True, False)
mItem.ToolTip = IIf(String.IsNullOrEmpty(tabView.TabToolTip), _
"", tabView.TabToolTip)
InnerMenu.Items.Add(mItem)
index += 1
Next
InnerMultiView = New MultiView()
InnerMultiView.ID = "tigerMltView"
For Each tabView As TabularView In Views
InnerMultiView.Views.Add(tabView)
Next
If InnerMultiView.Views.Count >= 0 AndAlso ActiveIndex < _
InnerMultiView.Views.Count Then
InnerMultiView.ActiveViewIndex = ActiveIndex
End If
AddHandler m_MultiView.ActiveViewChanged, AddressOf _
Mlt_ActiveIndexChanged
Me.Controls.Add(InnerMenu)
Me.Controls.Add(InnerMultiView)
End Sub
The Look and FeelThe Wrap-UpThe code that I have supplied along with this article contains many more features and functionality. These features exist only to provide additional functionality; however, they do not impact the Updates
| ||||||||||||||||||||