ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Migrating to ASP.NET
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @

Variable Name Prefixes
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Build Your Own ASP.NET Server Control Component
aka. <my:Component... Runat="Server" />


Here will deliver a simple tutorial guide you how to build a component using VB.NET, and the steps using it with ASP.NET Web Page.

This component will generate the bullet or numbering beside your list.

Below is the coding of the component

Step1: Copy the code below save it as "ShowList.vb" filename.

================== Code Listing: ShowList.vb ========================
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Collections
Namespace listControl
Public Class ShowList: Inherits Control
Private _dataSource As IEnumerable
Public Property DataSource As IEnumerable
  Return _dataSource
End Get
  _dataSource = Value
End Set
End Property
Public Title As String
Public Format As String
Protected Overrides Sub OnDataBinding (e As EventArgs)
  Dim DataEnum As IEnumerator
  Dim ltlLiteral As LiteralControl
  Dim lstBeginFormatTag As String
  Dim lstEndFormatTag As String
  Controls.Add(New LiteralControl("<b>" & Title & "</b>"))
  Select Case Format.ToLower()
    Case "number"
      lstBeginFormatTag = "<OL>"
      lstEndFormatTag = "</OL>"
    Case "bullet"
      lstBeginFormatTag = "<UL>"
      lstEndFormatTag = "</UL>"
  End Select
  If Format.ToLower() <> "number" AND Format.ToLower() <> "bullet" Then
    Controls.Add(New LiteralControl("<br><font color='red'>" _
	  & "Error Message: Undefined ""Format"" Property, either " _
	  & """number"" or ""bullet""</font><br>"))
    If Not DataSource Is Nothing
      DataEnum = DataSource.GetEnumerator()
      Controls.Add(New LiteralControl(lstBeginFormatTag))
      While (DataEnum.MoveNext())
        ltlLiteral = New LiteralControl (DataEnum.Current.ToString())
        Controls.Add(New LiteralControl("<LI>"))
        Controls.Add(New LiteralControl("</LI>"))
      End While
      Controls.Add(New LiteralControl(lstEndFormatTag))
      Controls.Add(New LiteralControl("<br><font color='red'>" _
        & "Data Not Found!</font><br>"))
    End If
  End If
End Sub
End Class
End Namespace
================== End of Code Listing ==============================

Step2: Compile and locate it at your web application root\bin folder.

vbc /t:library /r:System.dll,System.Web.dll ShowList.dll

Step3: Implement into your ASP.NET page, copy it and save it as "ListControl.aspx".

================== Code Listing: ListControl.aspx ===================
<%@ Register TagPrefix="listControl" Namespace="listControl"
<Script Runat="Server">
Sub Page_Load
    Dim theList As ArrayList
    theList = New ArrayList
    theList.Add ("Expresso")
    theList.Add ("Cappurino")
    theList.Add ("Coffee")
    theList.Add ("Mocha")
    dbBound.DataSource = theList
End Sub
<head><title>ListControl Demonstration</title></head>
<h2>Build Your Own Bullet and Numbering  Control Component</h2><br>
<listControl:ShowList id="dbBound" Title="Coffee Shop Menu"
  Format="bullet" Runat="Server"/>
================== End of Code Listing ==============================

In order to use the control, remember that locate the "ShowList.dll" file which is just generated into the web application root\bin folder. Inside your .aspx page, you need to attach this code on top

<%@ Register TagPrefix="listControl" Namespace="listControl" Assembly="ShowList"%>

Inside the content, you need to attach the code below to using the control.

<listControl:ShowList id="dbBound" Title="Coffee Shop Menu" Format="bullet" Runat="Server"/>

Description: Initially the Page_Load will bind the data into the control. You may bind the data with the database. For the "Format" property you can use either "bullet" or "number" to display your list. The "Title" property, it is just a title for the listing and in "BOLD" format.

Thanks for reading and try it out. Any suggestion or recommendation about this control are welcome reply to me.

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers