|
Home Preview the Book Chapter 15, TOC Part 16
Previous:
Rendering the Navigation HTML
Next:
Developing a Breadcrumb Control
Embedding a Custom Control in a User Control
In VB Snippets, the navigation custom control is enclosed within the u_navigate.ascx user control. You can register a custom control in a user control in the same way as you do in a Web page. Figure 15-11 shows the Design view of the navigation menu user control.
Figure 15-11. For design purposes, the navigation menu user control encloses a custom control within a table containing graphical elements.

The code for the navigation menu user control (Listing 15-6) provides the property values required by the custom control it encloses. The code instantiates the ResourceManager class and sets the smaccNav.ResourceManager property to reference it before using its own CurrentIndex property to set the smaccNav.CurrentIndex property.
Listing 15-6.The u_navigate.ascx.vb User Control Code
Option Strict On
Imports System.Resources
Public MustInherit Class u_navigate
Inherits System.Web.UI.UserControl
Protected WithEvents smaccNav As C15_Ctl_Lib.Navigation
[Designer generated code omitted]
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim rm As ResourceManager
rm = New ResourceManager("Chapter_15.strings", GetType(index).Assembly)
smaccNav.ResourceManager = rm
smaccNav.CurrentIndex = _CurrentIndex
End Sub
Private _CurrentIndex As Integer = 0
Property CurrentIndex() As Integer
Get
Return _CurrentIndex
End Get
Set(ByVal Value As Integer)
_CurrentIndex = Value
End Set
End Property
End Class
The navigation menu user control makes it a trivial task to output the HTML for the left-hand cell of each VB Snippets Web page. For example, the following lines form the complete specification for the left-hand cell of
index.aspx:
<td vAlign="top">
<sma:nav id="smaNav" runat="server" currentindex="0" />
</td>
The code for each page varies only according to the CurrentIndex value. In most cases, this value can be set once (as just shown) and forgotten. However, it is possible to navigate to a code_example page from the homepage, a search page, or a browse page. For the code_example page, therefore, the CurrentIndex property is set programmatically.
Previous:
Rendering the Navigation HTML
Next:
Developing a Breadcrumb Control
Home Preview the Book Chapter 15, TOC Part 16
|