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

How to get RadBinaryImage DataValue

4 Answers 360 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
sabarishbabu
Top achievements
Rank 1
sabarishbabu asked on 04 Sep 2009, 08:17 AM
Hi,

In UI,
I have 
   1. RadBinary image control to show Image from database
   2. Button control to save Image


I have two events
         1. Page_load()
         2. btnSave_Click()

In Page_Load()
         1. I'm getting Byte value from database and assigning it to RadBinaryImage.DataValue
In btnSave_Click
        1. I'm getting DataValue from RadBinaryImage control (assigned during page_load event)
         2. Save it into database
        3. But DataValue is null while retrieving from RadBinaryImage.


Code:
Page_Load
{
     if(!PostBack)
    {
        //Passing resoruceId and get resource object which contains Image value
         eFMResource resource = oAdminBase.GetResource(eResource.ResourceId);
        radBinaryImage.DataValue= resource.ImageValue;
    }
}

btnSave_Click
{
     eFMResource resource = new eFMResource ();
    //Getting DataValue from radBinaryImage and assign it to the object to save into db.
     resource.ImageValue = radBinaryImage.DataValue;
     oAdminBase.SaveResource(resource);
}


Thanks,
Sabarish.


4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 09 Sep 2009, 03:20 PM
Hello Sabarishbabu,

The DataValue is a property which specifies the source field from which the data will be passed as a byte array. This value is used only when the control is bound. After that the value is deleted and there is no way how you can retrieve it. You will need to get it from data base in order to use it for other purposes.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sérgio
Top achievements
Rank 1
answered on 08 Mar 2012, 12:41 PM
This is a workaround, saving an acess to database.
(it also can be very useful if this radBinaryImage is changeable by an upload control)


ASPX (add a hiddenfield):
<asp:HiddenField ID="hf_ImageString64Bytes" runat="server" Visible="false" />


Page_Load
{
     if(!PostBack)
    {
        //Passing resoruceId and get resource object which contains Image value 
         eFMResource resource = oAdminBase.GetResource(eResource.ResourceId);
        radBinaryImage.DataValue= resource.ImageValue;
        //// NEW CODE - Save the foto bytes at the hiddenfield
hf_ImageString64Bytes.Value = Convert.ToBase64String(resource.ImageValue);
    }
}

btnSave_Click
{
     eFMResource resource = new eFMResource ();
    //Getting DataValue from radBinaryImage and assign it to the object to save into db.
    //// OLD CODE
    // resource.ImageValue = radBinaryImage.DataValue;
    //// NEW CODE
    resource.ImageValue = Convert.FromBase64String(hf_ImageString64Bytes.Value);
     oAdminBase.SaveResource(resource);

}
0
Navin
Top achievements
Rank 2
answered on 28 Aug 2012, 09:16 AM
But there should be a method which can return the current bytes of image on the control.
0
Andrey
Telerik team
answered on 03 Sep 2012, 05:22 AM
Hi,

As my colleague Georgi said, you need to access the database field in order to get the binding data of the RadBinaryImage control. Current implementation of RadBInaryImage does not provide support for accessing its binding data.

All the best,
Andrey
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.
Tags
BinaryImage
Asked by
sabarishbabu
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Sérgio
Top achievements
Rank 1
Navin
Top achievements
Rank 2
Andrey
Telerik team
Share this question
or