Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports System.ComponentModel.Design
<DefaultProperty("Text"), DesignerAttribute(GetType(SuperCalendarDesigner), GetType(IDesigner)), ToolboxData(" <{0}:SuperDateTimePicker runat=server></{0}:SuperDateTimePicker>")> _
Public Class SuperDateTimePicker
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim mycalendar As SuperCalendar
Private _isMilitaryTime As Boolean = False
Private _isrequired As Boolean = False
Private _isreadonly As Boolean = False
Private _isdateonly As Boolean = False
Private _customlabel As String
Private _allowfuturedate As Boolean = False
Private _disablecalenderpopup As Boolean = False
Protected WithEvents datebox As TextBox
Protected WithEvents myseperator As Label
Protected WithEvents timebox As SuperTimePicker
WithEvents mytimevalidator As RequiredFieldValidator '''''''This appears to do NOTHING, should we erase this line?
WithEvents mydatevalidator As RequiredFieldValidator
WithEvents mydatecustomValidator As CustomValidator
'following attribute saves to viewstate, however,
'this is for TESTING only. The viewstate inclusions should
'be removed once testing is complete, and then simply flip the
'_isMilitaryTime private variable to default true on instantiation
'for military time
<DefaultValue(False)> Public Property IsMilitaryTime() As Boolean
Get
If Not Me.ViewState("ismilitarytime") Is Nothing Then
Return Me.ViewState("ismilitarytime")
Else
Return Me.Page.Application.Item("IsMilitaryTime")
End If
End Get
Set(ByVal Value As Boolean)
_isMilitaryTime = Value
Me.ViewState.Add("ismilitarytime", Value)
End Set
End Property
Public Property AllowFutureDate() As Boolean
Get
If Not Me.ViewState("allowfd") Is Nothing Then
Return Me.ViewState("allowfd")
Else
Return _allowfuturedate
End If
End Get
Set(ByVal Value As Boolean)
_allowfuturedate = Value
Me.ViewState.Add("allowfd", Value)
End Set
End Property
Public Property CustomLabel() As String
Get
If Not Me.ViewState("customerror") Is Nothing Then
Return Me.ViewState("customerror")
Else
Return _customlabel
End If
End Get
Set(ByVal Value As String)
_customlabel = Value
Me.ViewState.Add("customerror", Value)
End Set
End Property
<DefaultValue(False)> Public Property DisableCalendarPopUp() As Boolean
Get
Return _disablecalenderpopup
End Get
Set(ByVal Value As Boolean)
_disablecalenderpopup = Value
End Set
End Property
Public Property DateOnly() As Boolean
Get
Return _isdateonly
End Get
Set(ByVal Value As Boolean)
_isdateonly = Value
End Set
End Property
<DefaultValue(False)> Public Property IsRequired() As Boolean
Get
If Not Me.ViewState.Item("isrequired") Is Nothing Then
Return Me.ViewState.Item("isrequired")
Else
Return _isrequired
End If
End Get
Set(ByVal Value As Boolean)
_isrequired = Value
Me.ViewState.Add("isrequired", Value)
End Set
End Property
<DefaultValue(False)> Public Property IsReadOnly() As Boolean
Get
If Not Me.ViewState.Item("isreadonly") Is Nothing Then
Return Me.ViewState.Item("isreadonly")
Else
Return _isreadonly
End If
End Get
Set(ByVal Value As Boolean)
_isreadonly = Value
Me.ViewState.Add("isreadonly", Value)
End Set
End Property
Public Property DateTimeValue() As DateTime
Get
Dim _datetext As String = Me.ViewState.Item("_Date")
Dim _timetext As String = Me.ViewState.Item("_Time")
If _datetext Is Nothing Then
Return DateTime.MinValue
Else
If _timetext Is Nothing Then
Return Date.Parse(_datetext)
Else
Dim both As String
If Not IsMilitaryTime Then
both = String.Concat(_datetext, " ", _timetext)
Else
Dim r As String = ConvertToStandardTime(_timetext.Trim)
both = String.Concat(_datetext, " ", r)
End If
Return Date.Parse(both)
End If
End If
End Get
Set(ByVal Value As DateTime)
Me.ViewState.Add("_Date", Value.ToShortDateString)
If IsMilitaryTime Then
Me.ViewState.Add("_Time", ConvertToMilitaryTime(Value.ToShortTimeString))
Else
Me.ViewState.Add("_Time", Value.ToShortTimeString)
End If
End Set
End Property
Sub New()
MyBase.New()
Me.Width = Unit.Pixel(150)
End Sub
Public Sub ClearValue()
ensurechildcontrols()
Me.datebox.Text = String.Empty
If Not Me.DateOnly Then Me.timebox.Text = String.Empty
Me.DateTimeValue = DateTime.MinValue
End Sub
Private Sub adjustcontrolwidth()
'evalute space available for the three text boxes
Dim w As Unit = Unit.Pixel(Me.Width.Value * 0.5)
Dim c As Unit = Unit.Pixel(Me.Width.Value * 0.5)
datebox.Width = w
If Not _isdateonly Then timebox.Width = c
End Sub
Private Function ConvertToMilitaryTime(ByVal s As String) As String
Dim hourSubString As String = s.Substring(0, s.IndexOf(":"))
Dim ampmString As String = s.Substring(s.Length - 2, 2)
Dim minuteSubString As String = s.Substring(s.IndexOf(":") + 1, s.Length - s.IndexOf(" ") - 1)
Dim hourPart As Integer = Integer.Parse(hourSubString)
If ampmString = "AM" Then
If hourPart = 12 Then hourSubString = "00"
If hourPart < 10 Then hourSubString = hourSubString.Insert(0, "0")
Return String.Concat(hourSubString, minuteSubString)
Else
If hourPart < 12 Then hourPart = hourPart + 12
hourSubString = hourPart.ToString
Return String.Concat(hourSubString, minuteSubString)
End If
End Function
Private Function ConvertToStandardTime(ByVal s As String) As String
If IsMilitaryTime Then
Dim HourPart As Integer
If s.Length > 3 Then
Dim es As String = s.Substring(0, 2)
Dim i As Integer = Integer.Parse(es)
If i >= 12 Then
If i > 12 Then
HourPart = i - 12
Else
HourPart = 12
End If
s = s.Remove(0, 2)
s = s.Insert(0, HourPart.ToString)
s = String.Concat(s, " PM")
If HourPart > 9 Then
s = s.Insert(2, ":")
Else
s = s.Insert(1, ":")
End If
Else 'i = 12 or less
If i = 0 Then
s = s.Remove(0, 2)
s = s.Insert(0, "12")
s = s.Insert(2, ":")
ElseIf i < 10 Then
s = s.Remove(0, 1)
s = s.Insert(1, ":")
Else
s = s.Insert(2, ":")
End If
s = String.Concat(s, " AM")
End If
Else
'length of time in textbox = 3
Dim es As String = s.Substring(0, 1)
Dim i As Integer = Integer.Parse(es)
If i = 0 Then
s = s.Remove(0, 1)
s = s.Insert(0, "12")
s = s.Insert(2, ":")
Else
s = s.Insert(1, ":")
End If
s = String.Concat(s, " AM")
End If
Return s
Else
'we are in standardtime, but must convert 12:35p to 12:35 PM
s = s.Insert(s.Length - 1, " ")
s = s.Concat(s, "M")
Return s
End If
End Function
Private Function BuildDateBoxValidator()
Dim mys As New StringBuilder(800)
'mys.Append("<script language=""javascript"">" & ControlChars.CrLf)
'mys.Append("function BlurCheckSuperDate(obj){")
'mys.Append("someStr = obj.value;")
'mys.Append("if (SuperDateIsDate(someStr) == false){ obj.value="""";}}")
'mys.Append("</script>")
mys.Append("<script language=""javascript"">" & ControlChars.CrLf)
mys.Append("function SuperDateIsDate(source,args){")
mys.Append("if (args.Value.length == 0){ args.IsValid=true;return;}")
mys.Append("var dateStr = args.Value;")
mys.Append("var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;")
mys.Append("var matchArray = dateStr.match(datePat);")
mys.Append("if (matchArray == null){ args.IsValid=false; return;}")
mys.Append("month=matchArray[1]; day=matchArray[3]; year=matchArray[5];")
mys.Append("if (month < 1 || month > 12) { args.IsValid=false; return;}")
mys.Append("if (day < 1 || day >31) { args.IsValid=false; return;}")
mys.Append("if ((month==4 || month==6 || month==9 || month==11) && day==31){ args.IsValid=false; return;}")
mys.Append("if (year < 1900){ args.IsValid=false;return;}")
mys.Append("if (month==2) { var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));")
mys.Append("if (day > 29 || (day==29 && !isleap)) {args.IsValid=false;return;}}")
mys.Append("var parentCtl = source.parentNode.parentNode.firstChild.firstChild;")
mys.Append("if (parentCtl.isfd==null){")
mys.Append("var datedifference=0; dateNow =new Date(); compDate = new Date(year,month-1,day); datedifference=dateNow-compDate; if (datedifference < -86400000) {args.IsValid=false;source.title='Future Date not allowed';return;} ")
mys.Append("}")
mys.Append("args.IsValid=true; return;")
mys.Append("}")
mys.Append("</script>")
Return mys.ToString
End Function
Private Function BuildDateBoxKeyPressValidator()
Dim mys As New StringBuilder(800)
mys.Append("<script language=""javascript"">" & ControlChars.CrLf)
mys.Append("function validateDateBoxKeypress(e,obj){")
mys.Append("if (e.keyCode==13){ blockEnter(e);return false;}")
mys.Append("var proceed; var tempStr = obj.value; tempStr += String.fromCharCode(e.keyCode); var fChar = tempStr.charAt(tempStr.length - 2);")
mys.Append("if (tempStr.length > 7){ var match1 = tempStr.indexOf(""/"");var match2 = tempStr.indexOf(""/"",match1+1);if ((tempStr.length - match2 -1 <= 4) && (e.keyCode > 47 && e.keyCode <58)) {return true;}}")
mys.Append("switch (tempStr.length){case 1:if ((e.keyCode >47 && e.keyCode<58)||e.keyCode==32){if (e.keyCode>47 && e.keyCode<58) return true;if (obj.value.length==0) tempf1d = new Date();var tempf1mm=tempf1d.getMonth()+1;obj.value=tempf1mm+'/'+tempf1d.getDate()+'/'+tempf1d.getFullYear();try{document.all(obj.id.substring(0,obj.id.indexOf('_')) + '_TimeBox_TimeBoxHour').focus();}catch(erdt){findNextfocusControl(e);}}break; case 2: if (fChar.charCodeAt(0) ==48 && (e.keyCode >48 && e.keyCode < 58)) return true; if ((fChar.charCodeAt(0) > 48 && fChar.charCodeAt(0) <50) && ((e.keyCode >47 && e.keyCode <51) || e.keyCode == 47)) return true; if ((fChar.charCodeAt(0) > 48 && fChar.charCodeAt(0) < 58) && e.keyCode == 47) return true; break;")
mys.Append("case 3: if (fChar.charCodeAt(0) ==47 && (e.keyCode >47 && e.keyCode< 58)) return true; if (e.keyCode == 47 && (fChar.charCodeAt(0) > 47 && fChar.charCodeAt(0) <58)) return true; break;")
mys.Append("case 4: if (fChar.charCodeAt(0) == 47 && (e.keyCode >47 && e.keyCode <58)) return true; if (fChar.charCodeAt(0) ==48 && (e.keyCode >48 && e.keyCode <58)) return true;")
mys.Append("if ((fChar.charCodeAt(0) >48 && fChar.charCodeAt(0) <51) && (e.keyCode > 46 && e.keyCode <58)) return true; if (fChar.charCodeAt(0) ==51 && (e.keyCode >46 && e.keyCode <50)) return true; break;")
mys.Append("case 5: var firstmatch = tempStr.indexOf(""/"");var secondmatch = tempStr.indexOf(""/"",firstmatch+1);")
mys.Append("if (secondmatch < 0 && (firstmatch == 1 && e.keyCode >47)) return false; if (fChar ==""/"" && (e.keyCode >48 && e.keyCode <51)) return true; if (fChar == ""0"" && (e.keyCode > 48 && e.keyCode < 58)) return true;")
mys.Append("if (fChar == ""0"" && e.keyCode == 47 && firstmatch == 1) return true; if ((fChar.charCodeAt(0) > 48 && fChar.charCodeAt(0) < 58) && e.keyCode == 47) return true; if ((fChar == ""1"" || fChar == ""2"" ) && (e.keyCode >47 && e.keyCode <58)) return true;")
mys.Append("if (fChar == ""3"" && (e.keyCode == 48 || e.keyCode == 49)) return true; break;")
mys.Append("case 6: var myarray = tempStr.split(""/"");if (e.keyCode == 47) {if (myarray.length == 3) { return true;}")
mys.Append("else { if (tempStr.charCodeAt(4) == 47 && (e.keyCode > 48 && e.keyCode <51)) return true; if (tempStr.charCodeAt(4) == 49 && (e.keyCode >55 && e.keyCode <58)) return true;")
mys.Append("if (tempStr.charCodeAt(4) == 50 && (e.keyCode >47 && e.keyCode <50)) return true;}} else{ if ((e.keyCode >48 && e.keyCode <51) && fChar.charCodeAt(0) == 47) return true; if (myarray.length == 3 && fChar.charCodeAt(0) > 47 && fChar.charCodeAt(0) <58) return true;}break;")
mys.Append("case 7:if (tempStr.charCodeAt(5) == 47 && (e.keyCode > 48 && e.keyCode <51)) return true;if (tempStr.charCodeAt(5) == 49 && (e.keyCode >55 && e.keyCode <58)) return true;if (tempStr.charCodeAt(5) == 50 && (e.keyCode >47 && e.keyCode <50)) return true;")
mys.Append("var match1 = tempStr.indexOf(""/""); var match2 = tempStr.indexOf(""/"",match1+1); if ((tempStr.length - match2 -1 <= 4) && (e.keyCode > 47 && e.keyCode <58)) return true;break;")
mys.Append("}return false;}</script>")
Return mys.ToString
End Function
Private Function BuildCalendarJavaScript() As String
Dim mys As New StringBuilder(3390)
mys.Append("<script language=""javascript"">" & ControlChars.CrLf)
mys.Append("var input_date;var d = new Date();var dc;var monthname=new Array(""Jan"",""Feb"",""Mar"",""Apr"",""May"",""Jun"",""Jul"",""Aug"",""Sep"",""Oct"",""Nov"",""Dec"");var data = new Array(6);data[0] = new Array(0,0,0,0,0,0,0);data[1] = new Array(0,0,0,0,0,0,0);data[2] = new Array(0,0,0,0,0,0,0);data[3] = new Array(0,0,0,0,0,0,0);data[4] = new Array(0,0,0,0,0,0,0);data[5] = new Array(0,0,0,0,0,0,0);")
mys.Append("function chg(k,obj) {var parentelement = obj;d.setMonth(d.getMonth() + k);document.getElementById(parentelement + 'month_year').innerHTML = monthname[d.getMonth()] + ' ' + d.getFullYear();var dd = new Date(d);for (i=0;i<6;i++) for (j=0;j<7;j++) data[i][j] = 0;dd.setDate(1);i = 0;do { data[i][dd.getDay()] = dd.getDate();if (dd.getDay() == 6) i++;dd.setDate(dd.getDate() + 1);} while (dd.getDate() != 1); var dn = new Date();for (i=0;i<6;i++) for (j=0;j<7;j++) if (data[i][j] == 0) { document.getElementById(parentelement + ""c"" +i+""""+j).innerHTML= "" "";document.getElementById(parentelement + ""c"" +i+""""+j).className = ""day_out"";}")
mys.Append("else{ document.getElementById(parentelement + ""c"" +i+""""+j).innerHTML= data[i][j]; document.getElementById(parentelement + ""c"" +i+""""+j).className = ""day""; if (dc != undefined){ if (dc.getDate() == data[i][j]) document.getElementById(parentelement + ""c"" +i+""""+j).className = ""day_c"";} else{ if (dn.getDate()==data[i][j]) document.getElementById(parentelement + ""c"" +i+""""+j).className = ""day_c"";}}dc=null;}")
mys.Append(Environment.NewLine)
mys.Append("function setDate(i,j,obj) { var parentelement = obj; if (data[i][j]!=0) { m = d.getMonth()+1; input_date.value= m + ""/"" + data[i][j] + ""/"" + d.getFullYear();} document.getElementById(parentelement + 'avkCalendar').style.visibility='hidden'; try{document.all(obj + '_TimeBox_TimeBoxHour').focus();}catch(erdt){}}")
mys.Append(Environment.NewLine)
mys.Append("function getDate(cel,obj) { var parentelement=obj; input_date = cel; if (cel.value.length !=0) { d = new Date(cel.value); if (d == 'NaN') d = new Date();dc = new Date(d); }else{d=new Date();dc = new Date();} chg(0,parentelement); var alldivs = document.all.tags('DIV'); for (var i=0; i<alldivs.length;i++){if (alldivs[i].title=='DropDown'){DropDownClosePopUp(alldivs[i].id) }};hdExternal(); document.getElementById(parentelement + 'avkCalendar').style.visibility = ""visible""; }")
mys.Append("function hd(obj) {document.getElementById(obj+'avkCalendar').style.visibility='hidden'; } function setHandler() {return ""Encoding Completed"";}")
mys.Append("</script>")
Return mys.ToString
End Function
Protected Overrides Sub CreateChildControls()
'create all child controls
'create datebox
datebox = New TextBox
datebox.ID = "DateBox"
datebox.CssClass = Me.CssClass
datebox.MaxLength = 10
datebox.Attributes.Add("onkeydown", "return blockEnter(event);")
datebox.ReadOnly = _isreadonly
If Not DateTimeValue = DateTime.MinValue Then datebox.Text = Me.DateTimeValue.ToShortDateString
'''''AddHandler datebox.TextChanged, AddressOf datetimebox_textchanged
Controls.Add(datebox)
If Not _isdateonly Then
myseperator = New Label
Me.Controls.Add(myseperator)
timebox = New SuperTimePicker
timebox.ID = "TimeBox"
timebox.CssClass = Me.CssClass
timebox.IsReadOnly = _isreadonly
timebox.IsMilitaryTime = Me.IsMilitaryTime
''''''AddHandler timebox.TextChanged, AddressOf datetimebox_textchanged
Controls.Add(timebox)
End If
Dim c As Boolean = Me.IsReadOnly
mydatevalidator = New RequiredFieldValidator
mydatevalidator.EnableClientScript = True
mydatevalidator.Text = ""
mydatevalidator.ToolTip = "Date field is required"
mydatevalidator.Display = ValidatorDisplay.Dynamic
mydatevalidator.CssClass = "error1"
mydatevalidator.ControlToValidate = "DateBox"
Me.Controls.Add(mydatevalidator)
mydatecustomValidator = New CustomValidator
mydatecustomValidator.EnableClientScript = True
mydatecustomValidator.Text = ""
mydatecustomValidator.ToolTip = "Date is not a valid date"
mydatecustomValidator.CssClass = "error1"
mydatecustomValidator.Display = ValidatorDisplay.Dynamic
mydatecustomValidator.ClientValidationFunction = "SuperDateIsDate"
mydatecustomValidator.ControlToValidate = "DateBox"
Controls.Add(mydatecustomValidator)
End Sub
Private Sub datetimebox_textchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles datebox.TextChanged, timebox.TimeBoxChanged
'might have to convert to standard time, who the fuck knows
If datebox.Text = String.Empty Then
Me.DateTimeValue = DateTime.MinValue
If Not _isdateonly Then Me.timebox.Text = String.Empty
Else
If Not _isdateonly Then
Try
If Me.timebox.Text = String.Empty Then
Me.DateTimeValue = Date.Parse(Me.datebox.Text)
Else
'this line was breaking so surrounded it with an IF statement
If Not Me.IsMilitaryTime Then
'ORIGINAL STATEMENT before attemptimg ismilitarytime conversion 9/01
Me.DateTimeValue = Date.Parse(Me.datebox.Text & " " & Me.timebox.Text)
''''''''''''''''
Else
Me.DateTimeValue = Date.Parse(Me.datebox.Text & " " & Me.ConvertToStandardTime(Me.timebox.Text))
End If
End If
Catch ex As Exception
Me.DateTimeValue = DateTime.MinValue
End Try
Else
Me.DateTimeValue = Date.Parse(Me.datebox.Text)
End If
End If
End Sub
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
'ensure child controls have been created
ensurechildcontrols()
output.AddStyleAttribute("Z-INDEX", Me.Style.Item("Z-INDEX"))
output.RenderBeginTag(HtmlTextWriterTag.Div)
output.AddAttribute("cellpadding", "0")
output.AddAttribute("cellspacing", "0")
output.AddAttribute("border", "0")
output.RenderBeginTag(HtmlTextWriterTag.Table)
output.RenderBeginTag(HtmlTextWriterTag.Tr)
RenderChildren(output)
output.RenderEndTag()
If Not Me.IsReadOnly Then
output.RenderBeginTag(HtmlTextWriterTag.Tr)
If Not Me._isdateonly Then output.AddAttribute("colspan", "3")
output.RenderBeginTag(HtmlTextWriterTag.Td)
Dim mycalendar As New SuperCalendar
mycalendar.ParentElement = Me.ID
mycalendar.ID = mycalendar.ClientID
'mycalendar.Attributes.CssStyle.Add("z-index", "1000")
mycalendar.RenderControl(output)
output.RenderEndTag() 'td
output.RenderEndTag() 'tr
End If
output.RenderEndTag() 'table
output.RenderEndTag() 'div
End Sub
Friend Class SuperCalendar
Inherits System.Web.UI.HtmlControls.HtmlControl
Private _parentelement As String
Public Property ParentElement() As String
Get
Return _parentelement
End Get
Set(ByVal Value As String)
_parentelement = Value
End Set
End Property
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
generateCalendarTableDiv(writer)
End Sub
Private Sub generateCalendarTableDiv(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim s As String
s = "<div id="""
s &= _parentelement & "avkCalendar"""
s &= "class=""calendar""><table class=""calendar"" ID=""Table1""><tr><td onClick=""chg(-1,'" & ParentElement & "');"" class=""nav"">«</td>"
s &= "<td colspan=""4"" id=""" & _parentelement
s &= "month_year"" align=""center""></td><td onClick=""chg(1,'" & _parentelement & "');"" class=""nav"">»</td><td class=""closew"" onClick=""hd('" & _parentelement
s &= "')"">x</td></tr>"
writer.WriteLine(s)
'write days in next row
writer.RenderBeginTag(HtmlTextWriterTag.Tr)
Dim days As String() = {"Su", "Mo", "Tu", "Wd", "Th", "Fr", "St"}
For i As Integer = 0 To days.Length - 1
writer.AddAttribute("class", "wd")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(days(i))
writer.RenderEndTag()
Next
writer.RenderEndTag() '</tr>
'WRITE day number in next 5 rows, each with 7 columns
'assign an onclick attribute to each cell
'client-side javascript styles the selected date as bold
For i As Integer = 0 To 5
writer.RenderBeginTag(HtmlTextWriterTag.Tr)
For j As Integer = 0 To 6
writer.AddAttribute("onclick", "setDate(" & i.ToString & "," & j.ToString & ",'" & _parentelement & "')")
writer.AddAttribute("class", "day")
writer.AddAttribute("id", _parentelement & "c" & i.ToString & j.ToString)
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(" ")
writer.RenderEndTag()
Next
writer.RenderEndTag()
Next
writer.Write("</table>")
writer.Write("</div>")
End Sub
End Class '//end of SuperCalendar class definition
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If Me.IsReadOnly Then
Me.CssClass = "flat"
Else
Me.CssClass = "flatedit"
End If
Me.datebox.Attributes.Clear()
If Not Me.DateOnly Then Me.timebox.Attributes.Clear()
Me.datebox.ReadOnly = Me.IsReadOnly
If Not Me.DateOnly Then Me.timebox.IsReadOnly = Me.IsReadOnly
If Not DateTimeValue = DateTime.MinValue Then
Me.datebox.Text = Me.DateTimeValue.ToShortDateString
If Not _isdateonly Then
If Not IsMilitaryTime Then
Me.timebox.Text = Me.DateTimeValue.ToShortTimeString
Else
Me.timebox.Text = Me.ConvertToMilitaryTime(Me.DateTimeValue.ToShortTimeString)
End If
End If
Else
Me.datebox.Text = String.Empty
If Not _isdateonly Then Me.timebox.Text = String.Empty
End If
Me.datebox.CssClass = Me.CssClass
If Not _isdateonly Then Me.timebox.CssClass = Me.CssClass
Me.mydatecustomValidator.CssClass = "error1"
Me.mydatevalidator.CssClass = "error1"
If Me.AllowFutureDate Then datebox.Attributes.Add("isfd", "1")
If Not Me.IsReadOnly Then
'allow future date if set
If Not Me._disablecalenderpopup Then
If Not Page.IsClientScriptBlockRegistered("calendarFunctions") Then
' create and register the script on the page.
Page.RegisterClientScriptBlock("calendarFunctions", BuildCalendarJavaScript)
End If
End If
'//////
'register client-aware startup script to determine
'what regex should be applied to the date fields
'based on client's date locale.
'//////
If Not Page.IsClientScriptBlockRegistered("SuperDateTimeFn01") Then
Page.RegisterClientScriptBlock("SuperDateTimeFn01", BuildDateBoxValidator)
End If
If Not Page.IsClientScriptBlockRegistered("SuperDateTimeFn01a") Then
Page.RegisterClientScriptBlock("SuperDateTimeFn01a", BuildDateBoxKeyPressValidator)
End If
End If
If Not Page.IsClientScriptBlockRegistered("SuperControls") Then
Page.RegisterClientScriptBlock("SuperControls", "<script language=javascript src=Controlscript.js ></script>")
End If
mydatecustomValidator.Enabled = Not Me.IsReadOnly
If Me.IsRequired Then
mydatevalidator.Enabled = Not Me.IsReadOnly
Else
mydatevalidator.Enabled = False
End If
If Not Me.ViewState("customerror") Is Nothing Then
Dim c As String = Me.ViewState("customerror")
mydatevalidator.ToolTip = c
mydatevalidator.ErrorMessage = c
mydatecustomValidator.ErrorMessage = c
mydatecustomValidator.ToolTip = c
Me.timebox.CustomLabel = c
End If
If Not Me.IsReadOnly Then
If Not _disablecalenderpopup Then
datebox.Attributes.Add("onfocus", "DropDownCloseAll();getDate(this,'" & Me.ID & "');")
datebox.Attributes.Add("onClick", "getDate(this,'" & Me.ID & "');")
Else
datebox.Attributes.Add("onfocus", "DropDownCloseAll();")
End If
datebox.Attributes.Add("onKeyPress", "return validateDateBoxKeypress(event,this);")
End If
If Not _isdateonly Then
If Not DateTimeValue = DateTime.MinValue Then
If Not IsMilitaryTime Then
timebox.Text = Me.DateTimeValue.ToShortTimeString
Else
timebox.Text = Me.ConvertToMilitaryTime(Me.DateTimeValue.ToShortTimeString)
End If
End If
Me.myseperator.Style.Add("width", "2px")
If Not Me.IsReadOnly Then
timebox.Attributes.Add("onfocus", "DropDownCloseAll();")
Else
End If
End If
'adjust their width
adjustcontrolwidth()
End Sub
Private Sub SuperDateTimePicker_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
'ensurechildcontrols()
End Sub
Protected Overrides Sub RenderChildren(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.AddAttribute("valign", "top")
writer.AddAttribute("class", Me.CssClass)
writer.RenderBeginTag(HtmlTextWriterTag.Td)
Me.datebox.Style.Add("border", "none")
Me.datebox.RenderControl(writer)
writer.RenderEndTag()
If Not Me.DateOnly Then
writer.RenderBeginTag(HtmlTextWriterTag.Td)
Me.myseperator.RenderControl(writer)
writer.RenderEndTag()
If Not Me.IsReadOnly Then
writer.AddAttribute("class", Me.CssClass)
Else
writer.AddAttribute("class", "DateBoxSeperatorCont")
End If
writer.AddAttribute("nowrap", "")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
Me.timebox.RenderControl(writer)
writer.RenderEndTag()
End If
writer.AddAttribute("valign", "top")
writer.AddStyleAttribute("border", "none")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
Me.mydatevalidator.RenderControl(writer)
Me.mydatecustomValidator.RenderControl(writer)
writer.RenderEndTag()
End Sub
End Class '//end of DateTimePicker class definition
Public Class SuperCalendarDesigner
Inherits System.Web.UI.Design.ControlDesigner
Private myDT As SuperDateTimePicker
Public Overrides Function GetDesignTimeHtml() As String
Dim r As SuperDateTimePicker = CType(Me.Component, SuperDateTimePicker)
Dim s1 As String = "<table bgcolor=#FFFFFF height=5px border=1 cellpadding=0 cellspacing=0 width="
Dim s2 As String = "><tr><td> </td></tr></table>"
s1 = String.Concat(s1, r.Width.ToString)
Return String.Concat(s1, s2)
End Function
Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
myDT = DirectCast(component, SuperDateTimePicker)
MyBase.Initialize(component)
End Sub
End Class