Prevent a bad image from blowing up the code

2 posts, 0 answers
  1. Sandra
    Sandra avatar
    2 posts
    Member since:
    Sep 2011

    Posted 05 Jul 2012 Link to this post


    I was following the example for using a binary image with a listview to display images etc. allowing users to upload, and edit them.

    The code is great except in the event the user uploads a bad image, during postback when the listview is displayed it blows up and throws errors saying the binary data is corrupted.

    I know there should be a way to grab hold of the data during the ItemDataBound event, and catch the error, and ignore it or substitute the image with something stored on the website like a badimage.jpg

    can someone help with this thanks

  2. Andrey
    Andrey avatar
    836 posts

    Posted 10 Jul 2012 Link to this post


    The better approach is to validate the image upon uploading and to allow saving to the database only if the image was OK.

    If you use the ItemDataBound event to validate the images prior displaying them you will need to check every single image from the database and you will do it every time the Grid reloads its data. In the case I am suggesting you will need to check only one time the image prior inserting it into the database and thus you will be sure the image is OK.

    How you will validate the image depends on how it is stored and read, you could either user standard validator control or to provide custom validation settings.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. DevCraft R3 2016 release webinar banner
Back to Top