RadBinaryImage DataValue property Lost after postback

4 posts, 0 answers
  1. Eloy Paredes
    Eloy Paredes avatar
    4 posts
    Member since:
    Nov 2005

    Posted 13 Aug 2009 Link to this post

    Hi, I’m upload and set image successfully to RadBinaryImage (image show correctly), but when try to access to DataValue property for save in database, the DataValue property is null. I need access to property, from click event of button named "btnSave", after image is uploaded.

    Any Ideas.

    Thanks for help!


  2. Greg
    Greg avatar
    17 posts
    Member since:
    Mar 2009

    Posted 15 Aug 2009 Link to this post

    I am also in need of the same solution.
  3. Rosen
    Rosen avatar
    3247 posts

    Posted 17 Aug 2009 Link to this post

    Hello Greg,

    As you may know RadBinaryImage's DataValue will contain value only when control is populated and property's value will not be persisted across postbacks as storing such amount of data in the ViewState may cause performance and memory problems.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Greg
    Greg avatar
    17 posts
    Member since:
    Mar 2009

    Posted 17 Aug 2009 Link to this post

    I figured that it wouldn't be possible in Viewstate.

    However, I did discover that the controls ImageUrl property still points to a valid image.

    I tried doing a web request in the postback and retrieve the image data and it worked. However, I would imagine that this method would not be all that reliable.

    What I ended up doing (and the other user may want to try this) was to save the image as a temporary file:

                String strFilename = System.IO.Path.GetTempFileName();
                System.Drawing.Image imgInput = System.Drawing.Image.FromStream(RadUpload1.UploadedFiles[0].InputStream);
                System.Drawing.Imaging.ImageFormat fmtImageFormat = imgInput.RawFormat;
                imgInput.Save(strFilename, fmtImageFormat);
                ViewState["tempImage"] = strFilename;

    And then read it back on postback:

            // Get the image filename from viewstate
            String strFilename = ViewState["tempImage"].ToString();
            System.Drawing.Image image = System.Drawing.Image.FromFile(strFilename);

    I can either delete the temporary file myself or just let Windows clean it up for me.

Back to Top