I'm a bit new to this so please bear with me. I tried searching the forums for the answer, but perhaps I just don't know what to actually search for. Here's my situation:
I am using Visual Studio 2005 Standard SP1 to develop a website based front-end for an SQL database. I am trying to format user input from textboxes into the correct syntax for datetime in SQL (for example, 2008-01-20 18:08:00.000).
Basically there are two user input textboxes, and one hidden one. The first user textbox gets the date, the second gets the time (without seconds and such). The hidden textbox is where the other two are put together and where the value is drawn from when creating the input string for the database.
What I am trying to do is take TicketOpenedDate and TicketOpenedTime and put them in TicketOpenedDateTime and make sure they're in the correct format. The good news is that part works. (The user actually fills them out in the correct format for the database.)
The bad news is that it fills in the ":00.000" even when the user leaves TicketOpenedDate and TicketOpenedTime blank, and I'm not sure how to make it stop.
I want it to be able to respond to three different inputs.
1) If the user doesn't put anything into TicketOpenedDate and TicketOpenedTime, TicketOpenedDateTime needs to be blank.
2) If the user only fills out the date in TicketOpenedDate, TicketOpenedTime needs to given a value of "00:00", TicketOpenedDate and TicketOpenedTime need to be put together in TicketOpenedDateTime, and then have ":00.000" appended to it.
3) If the user fills out both textboxes, they need put together in TicketOpenedDateTime and then have ":00.000" appended to it.
Here is an example of the code I am using, I've tried several variations, but it should give you an idea of where my mind is at.
Dim TicketOpenedDate As TextBox = AddProblem.ContentTemplateContainer.FindControl("txtTicketOpenedDate") Dim TicketOpenedTime As TextBox = AddProblem.ContentTemplateContainer.FindControl("txtTicketOpenedTime") Dim TicketOpenedDateTime As TextBox = AddProblem.ContentTemplateContainer.FindControl("txtTicketOpenedDateTime") If TicketOpenedTime.Text Is "" And TicketOpenedDate.Text IsNot "" Then TicketOpenedTime.Text = "00:00" End If If TicketOpenedDate.Text IsNot "" Then TicketOpenedDateTime.Text = TicketOpenedDate.Text & " " & TicketOpenedTime.Text & ":00.000" End If
Thanks in advance,