I would like to make a custom control for phone numbers but I'm not quite sure how to do this. I'm a C# man myself by my new employer likes the
VB flavor, so I'm pretty new to this whole
VB side of things.
I want a phone number label that displays a formatted phone number. Currently in the databases they tend to store formatting with the numbers, which is ghetto. I want the presentation tier to provide all formatting in our future apps and I want to pull all of that formatted trash out of our databases.
So I guess for this one I'd like the format to look something like:
+1 (999) 999-9999
If there were no country prefix I want it to just display:
(999) 999-9999
If there is an extension I want it to show that too:
(999) 999-9999 Ext. 999
Or whatever.
All I have so far is my properties. Would I overload the Text property in the parent class?
In our database we typically store the area code, and number together. So the text that would be bound to this control would typically be a ten character string of numbers. So that confuses me. I can bind the country prefix to a new property I made called countryPrefix because thats stored in its own column in the database. Same goes for the extension number (in most cases). However the area code, and 7-digit number are typically stoted in one column in the database. So I cant just bind that to any one property because its really three properties....
I might be just over complicating this. Any advice or help anyone could provide would be greatly appreciated!
Code:
Imports Microsoft.VisualBasic
Public Class PhoneNumberTextBox
Inherits System.Web.UI.WebControls.Label
Private _countryPrefix As String
Private _areaCode As String
' In a telephone network the first three numbers of what we typically
' refer to as a "telephone number", is called the "exchange number"
Private _exchangeNumber As String
Private _customerNumber As String
Private _extensionNumber As String
Public Property countryPrefix()
Get
Return _countryPrefix
End Get
Set(ByVal value)
_countryPrefix = value
End Set
End Property
Public Property areaCode()
Get
Return _areaCode
End Get
Set(ByVal value)
_areaCode = value
End Set
End Property
Public Property exchangeNumber()
Get
Return _exchangeNumber
End Get
Set(ByVal value)
_exchangeNumber = value
End Set
End Property
Public Property customerNumber()
Get
Return _customerNumber
End Get
Set(ByVal value)
_customerNumber = value
End Set
End Property
Public Property extensionNumber()
Get
Return _extensionNumber
End Get
Set(ByVal value)
_extensionNumber = value
End Set
End Property
End Class
Neil Timmerman
Programmer II
School of Medicine
University of Missouri Columbia