How to catch this error

  • Thread starter Thread starter Howard
  • Start date Start date
H

Howard

A non-integer value is entered as student id
/grades.aspx?studentid=1283128sdf

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.

In aspx file

<asp:ObjectDataSource ID="object1" runat="server"
SelectMethod="GetScores" TypeName="GradeBook">
<SelectParameters><asp:QueryStringParameter Name="studentId"
Type="Int32" QueryStringField="studentid" DefaultValue="0"
/></SelectParameters>
</asp:ObjectDataSource>

The problem is I can't use try catch in the .aspx file. How can I solve this
problem
 
Howard said:
A non-integer value is entered as student id
/grades.aspx?studentid=1283128sdf
Input string was not in a correct format. [...]
The problem is I can't use try catch in the .aspx file.
How can I solve this problem

Well, you could check the string's length and contents (every
character must be a digit), but I don't know if you're saying you
don't have access to the source code at all, or that for some reason
you're just prohibited from doing exception handling.

Eq.
 
Hi,

Do not crosspost, you can get a good answer from any of the NGs as this is a
fairly trivial problem.

You need to validate the input string, you can do it in the client using any
of the Validators classes or in the server and then cancelling the action
and posting back an error.

Why can't you use try/catch in the server?
 
Best bet is using the validators. I don't know why you couldn't do the
exception handling... catch (FormatException fe) would be a snap.

~ John Fullmer
 
Back
Top