easyeman
10-26-2006, 10:54 AM
I'm having a slight problem I'm trying to prevent this error for inputting data into a textbox...I can probably figure it out but I just want to know what would be the best way to handle it.
Here's what I'm doing...I have a webpage set up that allows a customer to submit an order for calendars. What they do is go on and input the amount of Wall calendars they want into a textbox and then the amount of pocket calendars, along with other info such as the name, phone number, email, etc. I could probably just do what the other fields do in that it just pops up an error in a label saying something was not entered if a customer tries to submit the order without filling in all the info.
The problem I'm having is that well people obviously assume that if you leave a textbox blank for the quantity you want to order, that it will be 0. For example, if the customer just wanted 3 walls and no pocket, he would most likely put 3 for wall and leave the pocket textbox blank. Well with how my code is set up, if there is nothing in the field it just causes a server error and kills the page. The error says this:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 89: End If
Line 90:
Line 91: If CShort(tbPocket.Text) > 0 Then
Line 92: cart.AddItem(cartId, "PCALENDAR", "POCKET CALENDAR", CShort(tbPocket.Text), "1.00", 0.2, "N", "Y", 0.0)
Line 93: End If
Here is the section of code that is giving an if statement for input entered which I guess I need to update the code (it is in the code behind file for the calendars aspx page.
If CShort(tbLarge.Text) > 0 Then
cart.AddItem(cartId, "CALENDAR", "LARGE CALENDAR", CShort(tbLarge.Text), "5.00", 1.0, "N", "Y", 0.0)
End If
If CShort(tbPocket.Text) > 0 Then
cart.AddItem(cartId, "PCALENDAR", "POCKET CALENDAR", CShort(tbPocket.Text), "1.00", 0.2, "N", "Y", 0.0)
End If
I guess my question is what should I do in the code to tell the page that if a customer just leaves the field blank and submits it, that it will default the null value or empty textbox to be 0 so that it does go through and only enters what was entered.
I guess if anything I could just set an error so that they can't leave the textbox blank...such as right now it does not test if it is blank but if there is a number in there it tests if it falls into the range of 0-9...so I need to set up something to see if it is blank. That probably wouldn't be hard just to have an error display in a label saying something like "you cannot leave the box blank, please enter a value of 0-9". However I guess it would be nicer just to let a customer submit an order even if the textbox quantity is blank, since I know most people would not think to enter 0 and would just assume leaving it blank means it would be 0.
Hope that makes sense and I appreciate the help! I'm trying to figure out how to best fix that but cannot think of what to put in the code.
And I just thought of another idea...would it be easier just to have a Dropdown listbox for that instead of text? I guess I never thought of that but it does make more sense since they can only order 0-9, and that way they can just choose the amount and I wouldn't to worry about a wrong amount being entered or the box being empty. It could just default to "0" in the selection and then they choose. Would that be better and if so how would you suggest I set that up in place of the textbox? Thank!!
Here's what I'm doing...I have a webpage set up that allows a customer to submit an order for calendars. What they do is go on and input the amount of Wall calendars they want into a textbox and then the amount of pocket calendars, along with other info such as the name, phone number, email, etc. I could probably just do what the other fields do in that it just pops up an error in a label saying something was not entered if a customer tries to submit the order without filling in all the info.
The problem I'm having is that well people obviously assume that if you leave a textbox blank for the quantity you want to order, that it will be 0. For example, if the customer just wanted 3 walls and no pocket, he would most likely put 3 for wall and leave the pocket textbox blank. Well with how my code is set up, if there is nothing in the field it just causes a server error and kills the page. The error says this:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 89: End If
Line 90:
Line 91: If CShort(tbPocket.Text) > 0 Then
Line 92: cart.AddItem(cartId, "PCALENDAR", "POCKET CALENDAR", CShort(tbPocket.Text), "1.00", 0.2, "N", "Y", 0.0)
Line 93: End If
Here is the section of code that is giving an if statement for input entered which I guess I need to update the code (it is in the code behind file for the calendars aspx page.
If CShort(tbLarge.Text) > 0 Then
cart.AddItem(cartId, "CALENDAR", "LARGE CALENDAR", CShort(tbLarge.Text), "5.00", 1.0, "N", "Y", 0.0)
End If
If CShort(tbPocket.Text) > 0 Then
cart.AddItem(cartId, "PCALENDAR", "POCKET CALENDAR", CShort(tbPocket.Text), "1.00", 0.2, "N", "Y", 0.0)
End If
I guess my question is what should I do in the code to tell the page that if a customer just leaves the field blank and submits it, that it will default the null value or empty textbox to be 0 so that it does go through and only enters what was entered.
I guess if anything I could just set an error so that they can't leave the textbox blank...such as right now it does not test if it is blank but if there is a number in there it tests if it falls into the range of 0-9...so I need to set up something to see if it is blank. That probably wouldn't be hard just to have an error display in a label saying something like "you cannot leave the box blank, please enter a value of 0-9". However I guess it would be nicer just to let a customer submit an order even if the textbox quantity is blank, since I know most people would not think to enter 0 and would just assume leaving it blank means it would be 0.
Hope that makes sense and I appreciate the help! I'm trying to figure out how to best fix that but cannot think of what to put in the code.
And I just thought of another idea...would it be easier just to have a Dropdown listbox for that instead of text? I guess I never thought of that but it does make more sense since they can only order 0-9, and that way they can just choose the amount and I wouldn't to worry about a wrong amount being entered or the box being empty. It could just default to "0" in the selection and then they choose. Would that be better and if so how would you suggest I set that up in place of the textbox? Thank!!