|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article describes a simple way to mimic the appearance of Microsoft’s Outlook sidebar within an ASP.NET 2.0 web application. The approach is based upon the use of the existing This article includes a sample web application that presents an example of the approach in use. Getting StartedIn order to begin, unzip the downloaded files and open the project provided. Within the project, you will find a simple ASP.NET 2.0 application written in VB.NET; the web application contains a single web page (Default.aspx). The default.aspx page is built from a template table containing a sidebar, a header, and a main display area. In order to add a similar table to a project, create a new web page, open the “Layout” menu option, then select “Insert Table” from that option. The Insert Table dialog will then appear (Figure 1). From this dialog, select the “Template” option at the top of the dialog, then open the combo box to reveal the table options. Select the option showing “Header and Side”. When you click “OK”, a table in the format specified will be added to the open web page. You may wish to set the size properties for each of the table’s areas before adding any additional controls; it is typically easier to set up the proportions of the table when no controls are yet placed within its bounds. One thing you might want to do at this point is to set the sidebar area’s vertical alignment property to Once the table is placed and you are happy with its arrangement, it is time to add the controls necessary to support the appearance of Microsoft Outlook.
Figure 1: Insert Table Dialog in Visual Studio 2005 Take a look at Outlook (figure 2) and note that the sidebar is really pretty simple. There are a set buttons at the bottom of the sidebar and, above the buttons, is a display area used to display the controls relevant to the button selected. Whenever a new button is clicked from the bottom of the sidebar, the contents of the sidebar’s display area are updated to show the selection’s control options. At the top of the sidebar is a label that displays the contents of the sidebar. Whenever a new option is selected by clicking one of the buttons at the bottom of the sidebar, the label is updated to reflect the selection. Inside the sidebar’s display area, there can be additional collapsible panels that may be expanded or contracted to reveal or hide the panel’s content. These are very simple to construct from the Microsoft multi-view panel as well, and a simple example of such a panel is included in the demonstration. Figure 2: Microsoft Outlook With Sidebar Visible (on the left) Once the table has been configured, drag a You may drag some other controls inside each of the view panels; I merely placed some checkbox and radio button lists into the views for the purposes of this demonstration. However, the To demonstrate the collapsible panel, I constructed a simple user control that you will find in the demonstration project. The user control is entitled, “CollapsePanel.vb”; if you open it up for a look, you will see that it contains a single I placed a single The “ Partial Class CollapsePanel
Inherits System.Web.UI.UserControl
Protected Sub btnOpen_Click(ByVal sender As Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) _
Handles btnOpen.Click
MultiView1.ActiveViewIndex = 0
btnOpen.Visible = False
btnClose.Visible = True
End Sub
Protected Sub btnClose_Click(ByVal sender As Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) _
Handles btnClose.Click
MultiView1.ActiveViewIndex = -1
btnOpen.Visible = True
btnClose.Visible = False
End Sub
End Class
Once this user control has been built, add it to one of the views in the default.aspx page. The code for the main page is just about as simple as it is for the user control. Here again, the objective is merely to swap visible panels in response to button click events originating from the three buttons beneath the Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Me.MultiView1.SetActiveView(View1)
End If
End Sub
Here, if the page is not a post back, the The only task remaining is to set the event handlers for the three button controls used to select each of the three separate views contained in the Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.MultiView1.SetActiveView(Me.View1)
Button1.Font.Bold = True
Button2.Font.Bold = False
Button3.Font.Bold = False
txtHeader.Text = "Days"
End Sub
Protected Sub Button2_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Me.MultiView1.SetActiveView(Me.View2)
Button1.Font.Bold = False
Button2.Font.Bold = True
Button3.Font.Bold = False
txtHeader.Text = "Tools"
End Sub
Protected Sub Button3_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Me.MultiView1.SetActiveView(Me.View3)
Button1.Font.Bold = False
Button2.Font.Bold = False
Button3.Font.Bold = True
txtHeader.Text = "Cars"
End Sub
This is also pretty simple. In each event handler, the After setting the current That wraps it up. If you build and run the web application, you should see the following in your browser: (figure 3)
Figure 3: Demonstration Web Application If you click on each of the buttons, you should see the content of the sidebar update. If you select the “Cars” button, you should see the collapsible panel user control, and if you click on its icon, you should see it reveal and hide the contents of its
Figure 4: Collapsible Panel Closed
Figure 5: Collapsible Panel Opened
|
|||||||||||||||||||||||||||||||||||||||||||||||