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,
J'Tok

THe reason is for your usage of Is and IsNot. Try this here:

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 Nothing And TicketOpenedDate.Text IsNot Nothing Then
            TicketOpenedTime.Text = "00:00"
        End If
        If TicketOpenedDate.Text IsNot Nothing Then
            TicketOpenedDateTime.Text = TicketOpenedDate.Text & " " & TicketOpenedTime.Text & ":00.000"
        End If

Thank you for the response. However, I just tried what you suggested, and the exact same behavior is still exhibited.

- J'Tok

ok then do this:

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 Nothing And Not TicketOpenedDate.Text Is Nothing And TicketOpenedDate.length > 1 Then
            TicketOpenedTime.Text = "00:00"
        End If
        If Not TicketOpenedDate.Text Is Nothing And TicketOpenedDate.length > 1 Then
            TicketOpenedDateTime.Text = TicketOpenedDate.Text & " " & TicketOpenedTime.Text & ":00.000"
        End If

Change your find control methods too:

Dim TicketOpenedDate As TextBox = CType(AddProblem.ContentTemplateContainer.FindControl("txtTicketOpenedDate"), TextBox)
        Dim TicketOpenedTime As TextBox = CType(AddProblem.ContentTemplateContainer.FindControl("txtTicketOpenedTime"), TextBox)
        Dim TicketOpenedDateTime As TextBox = CType(AddProblem.ContentTemplateContainer.FindControl("txtTicketOpenedDateTime"), TextBox)
        If TicketOpenedTime.Text Is Nothing And Not TicketOpenedDate.Text Is Nothing And TicketOpenedDate.length > 1 Then
            TicketOpenedTime.Text = "00:00"
        End If
        If Not TicketOpenedDate.Text Is Nothing And TicketOpenedDate.length > 1 Then
            TicketOpenedDateTime.Text = TicketOpenedDate.Text & " " & TicketOpenedTime.Text & ":00.000"
        End If

Thank you! I had to make a few modifications to make it work exactly right, but you got me pointed onto the right path! WOO HOO!
I needed to be looking at length, was my problem all along. I knew it would be something simple like that.

Here's the final code:

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.Length = 0 And TicketOpenedDate.Text.Length > 1 Then
            TicketOpenedTime.Text = "00:00"
        End If
        If TicketOpenedDate.Text.Length > 1 Then
            TicketOpenedDateTime.Text = TicketOpenedDate.Text & " " & TicketOpenedTime.Text & ":00.000"
        End If

Thank you again,
J'Tok

Well also keep in mind for length, if you have to have 4 digits and a colon sign, then do some extra modification like remove all characters except for integers from the strings, then use substring to pull the first 2 characters, and the last 2 then place them correctly. I am sure it would mess up all time if they entered it in as:

0220 instead of 02:20 and if they entered 02;20, you know? :)

This question has already been answered. Start a new discussion instead.