ASP.NET MultiView Navigation – extending the View Control

I was working on a small proof-of-concept piece of code today using a somewhat complex assortment of ASP.NET View controls nested inside a MultiView. I was looking for an easy way to navigate amongst them so that a user could go to any one of the Views in any order they wanted to and was frustrated to find that although I could programmatically enumerate through each of them and say, add them to a drop down box, that there was no “Friendly Name” property for the View control and I was stuck using the actual name which doesn’t allow for spaces.

 

Well the last project I worked on had me writing quite a few user controls for the customer so this seemed like a perfect opportunity to give myself a gentle introduction to working with custom controls by extending an existing one…in this case, simply adding a “Friendly Name” property to a View control so I can build my navigation piece. Some of you ASP.NET veterans may be snickering at me, but those who know me know that I never really liked Web Application Development until the last project I was on…and that I still prefer WinForms or especially Compact Framework over ASP.NET. Anyways…

 

It turns out adding this property to the View control was far easier than I’d imagined it would be. Check out the code sample below:

 

   1:  Imports System.ComponentModel
   2:  Imports System.Web.UI
   3:  <ToolboxData("<{0}:BrainThumpViewPlus runat=server></{0}:BrainThumpViewPlus>")> _
   4:  Public Class BrainThumpViewPlus
   5:      Inherits System.Web.UI.WebControls.View
   6:      Private m_FriendlyName As String
   7:      Public Property FriendlyName() As String
   8:          Get
   9:              Return m_FriendlyName
  10:          End Get
  11:          Set(ByVal Value As String)
  12:              m_FriendlyName = Value
  13:          End Set
  14:      End Property
  15:  End Class
 
 

So with this freshly compiled and added to my web project, I’m able to add the following to my Page Load event to create my navigation scheme for the project I was working on:

 

   1:  Dim lItems As BrainThumpControlLibrary.BrainThumpViewPlus
   2:          For Each lItems In MainMultiView.Views
   3:              DropDownList1.Items.Add(lItems.FriendlyName)
   4:          Next
 

Sweet – short – simple :)

 

For those who are interested I’ll post a short “How-to” article complete with project source at a URL near you soon.

 

Now – to the more experienced ASP.NET folks out there…what would you have done because I’m interested in learning any easier ways. I’ve discovered one solution to my problem, but I’m sure it’s not the only one!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Wednesday, November 08, 2006 9:36 PM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)