Formview "Insert" Input string was not in a correct format

I have a formview bound to an objectdatasource and is "linked" to a custom object.  My fields on the form view look like:  <asp:TextBox ID="txtCarNumber" runat="server" Text='<%# Bind("CarNumber") %>' SkinID="txtNumberField" />.

When in "Insert" mode, when the "Insert" link is pressed, I have validation routines that check the values in the TextBoxs.  If the field should be an integer but is empty, I set it to "0".  For example,  I set txtCarNumber.Text = "0" and I let this pass the validation.  

The validation is passed (with no additional postbacks) and the "insert" method continues.  A new instance of my object is created and then the properties are set to the values in the formview.  
   public int CarNumber
        get { return carNumber; }
        set { carNumber = value; }

However, for property "CarNumber' in my object, the "value" is an empty string instead of the "0" I set the txtCarNumber.text to.  This causes an error because "CarNumber" must be an integer value.  

How can I make sure the object is bound to the values in textbox?  Is there away to "re-link" the textbox value to the "Bind()" value without doing a page postback?

Who is Participating?
weimhaConnect With a Mentor Author Commented:
It works when I set it to 0.  I accidently was forgeting about one field and it was causes the problem.  When I set it to 0 it works now.
orbulatConnect With a Mentor Commented:
just a quick thought
anything relating to "if (!IsPostBack) { xxxx }"  ?
prairiedogConnect With a Mentor Commented:
>>>If the field should be an integer but is empty, I set it to "0".  
How do you do it? With JavaScript?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.