This is a migrated thread and some comments may be shown as answers.

RadBinaryImage DataValue property Lost after postback

3 Answers 226 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Eloy Paredes
Top achievements
Rank 1
Eloy Paredes asked on 13 Aug 2009, 05:34 PM

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!

Eloy.

3 Answers, 1 is accepted

Sort by
0
Greg
Top achievements
Rank 1
answered on 16 Aug 2009, 01:46 AM
I am also in need of the same solution.
0
Rosen
Telerik team
answered on 17 Aug 2009, 03:56 PM
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.

Regards,
Rosen
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.
0
Greg
Top achievements
Rank 1
answered on 17 Aug 2009, 04:28 PM
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.

Greg
Tags
BinaryImage
Asked by
Eloy Paredes
Top achievements
Rank 1
Answers by
Greg
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or