What is the value past by the textbox?

Last post 07-03-2008 3:53 PM by shakeman_11. 2 replies.

Sort Posts:

  • What is the value past by the textbox?

    07-03-2008, 3:36 PM
    • Member
      8 point Member
    • shakeman_11
    • Member since 01-21-2008, 3:48 PM
    • Posts 21

    Hello,

    I am new to programming. Hope someone can help here.

    I am using formview to bind the dtabase to do some manipulations. e.g. edit, insert, delete. In my edit template, I have one textbox bind to a datetime column in the database. I have problem when input null/empty value into the textbox. My code for objectdatasource_inserting statement is here. I use this statement to assign the values from EditTemplate controls to parameters.

    Protected Sub CodedValueObjectDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles CodedValueObjectDataSource.Updating

    Dim NewExpriy_date As TextBox = FormView1.FindControl("row_expiry_dateTextBox")

    '--------------Dim other controls----------

    Dim ExpDate As DateTime

    If  string.IsNullOrEmpty("NewExpriy_date")  'I also tried NewExpriy_date.text = ""  Then

    ExpDate = SqlDateTime.Null  'DateTime.MinValue

    Else

    ExpDate = DateTime.Parse(NewExpriy_date.Text) 'Convert.ToDateTime(NewExpriy_date.Text)

    End If

    e.InputParameters("row_expiry_date") = ExpDate

    'Assign values to other parameters

    End Sub

    When input null/empty in row_expiry_dateTextBox, it seems like my if statement doesn't work and does not read statement ExpDate = SqlDateTime.Null; instead it reads ExpDate = DateTime.Parse(NewExpriy_date.Text) and give me error message "String was not recognized as a valid DateTime." I am wondering what is the value past by the textbox when I left it empty.

    BTW, my statement works when I type in a datatime value in the textbox.

    thanks in advance.

    B.

  • Re: What is the value past by the textbox?

    07-03-2008, 3:44 PM
    Answer
    • All-Star
      20,998 point All-Star
    • Jeev
    • Member since 11-24-2005, 12:49 PM
    • Posts 3,163

     change this as

    If  NewExpriy_date is Nothing orelse string.IsNullOrEmpty(NewExpriy_date.Text)   Then

    ExpDate = SqlDateTime.Null  'DateTime.MinValue

    Else

     

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: What is the value past by the textbox?

    07-03-2008, 3:53 PM
    • Member
      8 point Member
    • shakeman_11
    • Member since 01-21-2008, 3:48 PM
    • Posts 21

    Thanks Jeev.

     

Page 1 of 1 (3 items)