misformed QueryString Error / ObjectDataSource

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paxxer
    New Member
    • Jan 2009
    • 22

    misformed QueryString Error / ObjectDataSource

    Hi All,

    I'm using an URL?ID=F28C680E-BC0B-485D-8CFE-8BC29656BF71 as a method parameter for an objDataSource.

    That is a GUID from the query string.

    So in testing I wanted to see what would happen if a person browsed to the page without an ID field in the QueryString,

    And of course a error is thrown, "Can't covert 0000000-0000-0000-0000-000000 to a GUID"

    Which is expected.

    My Question is this: Where would I check that the ID isn't a proper GUID, prior to the ObjDataSource getting all upset?

    thanks
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Validate the parameter before you access the ObjDataSource.. ..
    First check the parameter where ever you are accessing the ObjDataSource.

    It's as simple as adding an If (MyParameterIsV alid) statement before accessing the ObjDataSource.

    Comment

    • Paxxer
      New Member
      • Jan 2009
      • 22

      #3
      looking for the right event

      Thanks Frinavale,

      Let me add some more details.

      There is no "code" in the code behind page. I have the ObjectDataSourc e acting as the dataobject for an asp:GridView. All of the "Accessing" is taking place behind the seens.

      So my question is actually:

      Which event is the correct place to check for the validity of the QueryString ID so I can cancel the ObjectDataSourc e, trying to use it as a parameter?

      Thanks

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Naturally you do not want to attempt to show content for something that doesn't exist.

        In this case, I would recommend that you do your validation in the Class that you have developed to server as your data source .

        In the case that the validation should fail throw a *custom exception.
        You can then catch this exception in yourPage Error Event in order to display something user friendly.

        For an example of how implement your data source Class in such a way that it throws an error see the ObjectDataSourc e Class.

        I found this interesting while researching your problem.


        *Please note that the article linked to has you inherit from BaseException, it should just be Exception because Exception is the base class for all Exceptions.

        Comment

        • Paxxer
          New Member
          • Jan 2009
          • 22

          #5
          Thanks for the efforts,

          Sure, I can "Make it work", with a hack here or there.

          But it seems that I should be able to cancel the selecting request on the ObjectDataSourc e before it raises an error.

          I couldn't find the event to do this in.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Have you considered dynamically creating the ObjectDataSourc e?
            You would have a lot more control over it in code.

            Check out this article. It has a lot of information there on the ObjectDataSourc e.

            Comment

            • Paxxer
              New Member
              • Jan 2009
              • 22

              #7
              I've moved on, with a workaround.

              I'm curious about which is the correct Event, not other workarounds.

              Thanks

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                The article that I linked you to suggests that you implement your validation rules in your Business Logic Layer (in your Class). However, the example they give doesn't include how to do this ("for simplicity sake").

                I've been reading up on this all day (thanks :)) and I'm almost certain that there is no event for this process.

                You'll either have to dynamically create the ObjectDataSourc e for the GridView at run time in order to handle validation before it's accessed, or you have to implement validation in your Class.

                -Frinny

                Comment

                Working...