How to get RadBinaryImage DataValue

5 posts, 0 answers
  1. sabarishbabu
    sabarishbabu avatar
    136 posts
    Member since:
    Apr 2009

    Posted 04 Sep 2009 Link to this post

    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.


  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 09 Sep 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sérgio
    Sérgio avatar
    9 posts
    Member since:
    Aug 2008

    Posted 08 Mar 2012 Link to this post

    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);

    }
  5. Navin
    Navin avatar
    1 posts
    Member since:
    Aug 2012

    Posted 28 Aug 2012 Link to this post

    But there should be a method which can return the current bytes of image on the control.
  6. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 03 Sep 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017