First up:
If you drag + drop a text box onto the web form, then you can in the property sheet set this:
So, display the property sheet for the text box, and select DateTimeLocal. You get a REALLY nice date + time picker - all with nice spinners etc. and you get this:
so the above will save you BOAT-LOADS of time and effort.
I suppose you could combine + cobbile + code your way though your custom dropdowns, but you REALLLY are far better off to use the built in date, or in this case date + time picker. The reason is simple:
If you drop two controls on a form, then you can have a start + end time, and in code because the date is included, then you can span across mid-night (or say take out a book or some equipment for several days). And then in code, you can test/check/see if the start time (and date) is less then the end time with this simple code:
Set the auto-post back of the text box = true, and then in code you can do this:
When you run the above, you get this:
So, you can "click" on the calendar. And TRY the mouse wheel to select time.
click on calendar again to confirm the results. You can ALSO type via keyboard, and it will prevent funny values etc.
So, our full markup for the above is this:
<body>
<form id="form1" runat="server">
<div style="float:left">
<asp:Label ID="Label1" runat="server" Text="Enter Start Time" Font-Size="Large"></asp:Label>
<br />
<asp:TextBox ID="txtStartTime" runat="server" TextMode="DateTimeLocal" Width="196px" Height="16px" AutoPostBack="True"></asp:TextBox>
</div>
<div style="float:left;margin-left:20px">
<asp:Label ID="Label2" runat="server" Text="Enter End Time" Font-Size="Large"></asp:Label>
<br />
<asp:TextBox ID="txtEndTime" runat="server" TextMode="DateTimeLocal" Width="196px" Height="16px" AutoPostBack="True"></asp:TextBox>
</div>
<div style="clear:both">
<h2 id="myMsg" runat="server"></h2>
</div>
</form>
</body>
And our full code behind is this:
Protected Sub txtStartTime_TextChanged(sender As Object, e As EventArgs) Handles txtStartTime.TextChanged
MyTimeCheck
End Sub
Protected Sub txtEndTime_TextChanged(sender As Object, e As EventArgs) Handles txtEndTime.TextChanged
MyTimeCheck()
End Sub
Sub MyTimeCheck()
If txtStartTime.Text <> "" And txtEndTime.Text <> "" Then
If txtStartTime.Text > txtEndTime.Text Then
Me.myMsg.InnerHtml = "Start time must be less then End Time"
Else
myMsg.InnerHtml = ""
End If
End If
End Sub
So I used mostly drag + drop. And then I used the property sheet (events), and clicked on the event stub to launch the code behind editor.
So if you follow above:
We did mostly drag + drop.
We wrote very little code - kind of like desktop developer (Access or VB6).
The MOUSE wheel works for the time picker - try it!!!!
The data is VERIFED to be date + time for you - no need for messy code to test/check the input format if you FORCE the text box to a date (or date + time in this case).
Now, I could perhaps follow up on your existing code, but I don't think it all that of a good idea when a nice date + time picker is built in for you.