locked
Hours Validation RRS feed

  • Question

  • User577622187 posted

    On the time entry page, if I enter nothing in the Hours text field, instead of getting a validation message ('Hours is a required value'), instead I abend with a message 'FormatException was unhandled by user code'.  Below that it says 'Input string was not in correct format'.

    The code it blows up is the first line in the AddEntry_Click subroutine:

    Dim timeEntry As TimeEntry = New TimeEntry(Page.User.Identity.Name, Convert.ToInt32(CategoryList.SelectedValue), Convert.ToDecimal(Hours.Text), DateTime.Now, UserList.SelectedValue)

    Below is the entire subroutine.  What do I need to do to prevent this from happening should the user not key in a value into Hours?

    ==============================================================

    Protected Sub AddEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddEntry.Click

    Dim timeEntry As TimeEntry = New TimeEntry(Page.User.Identity.Name, Convert.ToInt32(CategoryList.SelectedValue), Convert.ToDecimal(Hours.Text), DateTime.Now, UserList.SelectedValue)

    timeEntry.Description = Description.Text

    timeEntry.Save()

    Description.Text = String.Empty

    Hours.Text = String.Empty

    ProjectListGridView.DataBind()

    End Sub

    ===========================================================

    Sunday, July 2, 2006 10:51 AM

All replies

  • User-1790118103 posted
    I'm having the same problem. It shouldn't even get that far because of the validation, right? It should check the validation, realize hours is empty and display the error messages instead of trying to add the entry.
    Tuesday, April 24, 2007 2:15 PM
  • User555306248 posted
    You have to handle it manually
    Tuesday, April 24, 2007 11:46 PM
  • User555306248 posted
    Try to use RequiredField Validators
    Tuesday, April 24, 2007 11:47 PM