Listboxes with validation
I am creating a .net project and am adding custom renderers. I have this code for creating the date field into 3 listboxes, the Month, theDay and theYear. I would like to add an on_change() event (or some such mechanism) to change theDay from 1-31 to the appropriate number of days (I have to consider leap years too).
---------------- Beginning of code -------------------------
Imports System.ComponentModel
Imports System.Web.UI
<ToolboxData("<{0}:DateRenderer runat=server></{0}:DateRenderer>")> Class DateRenderer
Inherits AbstractFieldRenderer
Private Shared ReadOnly DEFAULT_DATE = Now()
Private Shared log As log4net.ILog = log4net.LogManager.GetLogger("DateRenderer")
Public Overloads Sub onInit(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init
Dim theMonth As New ListBox
'' theMonth.Width = Unit.Parse("21pt")
theMonth.ID = Me.ID & "_theMonth"
theMonth.Items.Add(New ListItem("Jan", "01"))
theMonth.Items.Add(New ListItem("Feb", "02"))
theMonth.Items.Add(New ListItem("Mar", "03"))
theMonth.Items.Add(New ListItem("Apr", "04"))
theMonth.Items.Add(New ListItem("May", "05"))
theMonth.Items.Add(New ListItem("Jun", "06"))
theMonth.Items.Add(New ListItem("Jul", "07"))
theMonth.Items.Add(New ListItem("Aug", "08"))
theMonth.Items.Add(New ListItem("Sep", "09"))
theMonth.Items.Add(New ListItem("Oct", "10"))
theMonth.Items.Add(New ListItem("Nov", "11"))
theMonth.Items.Add(New ListItem("Dec", "12"))
Me.Parent.Controls.Add(theMonth)
Dim theDay As New ListBox
'theDay.Width = Unit.Parse("14pt")
theDay.ID = Me.ID & "_theDay"
Dim i As Integer
For i = 1 To 31
theDay.Items.Add(New ListItem(i, i))
Next
Dim theYear As New ListBox
'theYear.Width = Unit.Parse("28pt")
theYear.MaxLength = 4
theYear.ID = Me.ID & "_lastFour"
Dim x As Integer = System.DateTime.Today.Year
For i = 1900 To x
theYear.Items.Add(New ListItem(i, i))
Next
Dim theMonthRequiredValidator As New RequiredFieldValidator
theMonthRequiredValidator.ControlToValidate = Me.ID & "_theMonth"
theMonthRequiredValidator.ErrorMessage = "Choose a month, this field is required."
theMonthRequiredValidator.Display = ValidatorDisplay.None
Dim theDayRequiredValidator As New RequiredFieldValidator
theDayRequiredValidator.ControlToValidate = Me.ID & "_theDay"
theDayRequiredValidator.ErrorMessage = "Choose a day, this field is required."
theDayRequiredValidator.Display = ValidatorDisplay.None
Dim theYearRequiredValidator As New RequiredFieldValidator
theYearRequiredValidator.ControlToValidate = Me.ID & "_theYear"
theYearRequiredValidator.ErrorMessage = "Choose a year, this field is required."
theYearRequiredValidator.Display = ValidatorDisplay.None
Me.Parent.Controls.Add(theMonthRequiredValidator)
Me.Parent.Controls.Add(theDayRequiredValidator)
Me.Parent.Controls.Add(theYearRequiredValidator)
Me.Parent.Controls.Add(theMonth)
Me.Parent.Controls.Add(theDay)
Me.Parent.Controls.Add(theYear)
End Sub
End Class
---------------- End of code -------------------------
Thanks for the help!
|