How to catch this error

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
 
P

Paul E Collins

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.
 
I

Ignacio Machin \( .NET/ C# MVP \)

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?
 
J

John Fullmer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top