How to catch this error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Howard

    #1

    How to catch this error

    A non-integer value is entered as student id
    /grades.aspx?stu dentid=1283128s df

    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.FormatEx ception: Input string was not in a correct
    format.

    In aspx file

    <asp:ObjectData Source ID="object1" runat="server"
    SelectMethod="G etScores" TypeName="Grade Book">
    <SelectParamete rs><asp:QuerySt ringParameter Name="studentId "
    Type="Int32" QueryStringFiel d="studentid" DefaultValue="0 "
    /></SelectParameter s>
    </asp:ObjectDataS ource>

    The problem is I can't use try catch in the .aspx file. How can I solve this
    problem


  • Mark Rae

    #2
    Re: How to catch this error

    "Howard" <howdy0909@yaho o.com> wrote in message
    news:evPrKc8gGH A.1244@TK2MSFTN GP04.phx.gbl...

    1) Please don't cross-post.

    2) Use a validator control



    Comment

    • Paul E Collins

      #3
      Re: How to catch this error

      Howard wrote:
      [color=blue]
      > A non-integer value is entered as student id
      > /grades.aspx?stu dentid=1283128s df
      > 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[/color]

      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.


      Comment

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

        #4
        Re: How to catch this error

        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?


        --
        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation


        "Howard" <howdy0909@yaho o.com> wrote in message
        news:evPrKc8gGH A.1244@TK2MSFTN GP04.phx.gbl...[color=blue]
        >A non-integer value is entered as student id
        > /grades.aspx?stu dentid=1283128s df
        >
        > 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.FormatEx ception: Input string was not in a
        > correct format.
        >
        > In aspx file
        >
        > <asp:ObjectData Source ID="object1" runat="server"
        > SelectMethod="G etScores" TypeName="Grade Book">
        > <SelectParamete rs><asp:QuerySt ringParameter Name="studentId "
        > Type="Int32" QueryStringFiel d="studentid" DefaultValue="0 "
        > /></SelectParameter s>
        > </asp:ObjectDataS ource>
        >
        > The problem is I can't use try catch in the .aspx file. How can I solve
        > this problem
        >[/color]


        Comment

        • John Fullmer

          #5
          Re: How to catch this error

          Best bet is using the validators. I don't know why you couldn't do the
          exception handling... catch (FormatExceptio n fe) would be a snap.

          ~ John Fullmer


          Howard wrote:[color=blue]
          > A non-integer value is entered as student id
          > /grades.aspx?stu dentid=1283128s df
          >
          > 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.FormatEx ception: Input string was not in a correct
          > format.
          >
          > In aspx file
          >
          > <asp:ObjectData Source ID="object1" runat="server"
          > SelectMethod="G etScores" TypeName="Grade Book">
          > <SelectParamete rs><asp:QuerySt ringParameter Name="studentId "
          > Type="Int32" QueryStringFiel d="studentid" DefaultValue="0 "
          > /></SelectParameter s>
          > </asp:ObjectDataS ource>
          >
          > The problem is I can't use try catch in the .aspx file. How can I solve this
          > problem[/color]

          Comment

          Working...