Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > BinaryImage > Reloading Binary Image

Not answered Reloading Binary Image

Feed from this thread
  • Francisco avatar

    Posted on Mar 7, 2011 (permalink)

    Hello,

    I'm using a RadBinaryImage to show an image stored in a folder. Using a RadAsyncUpload, the users are able to upload a new image and the RadBinaryImage will work as a thumbnail. This is working correctly, the thumbnail is reloaded correctly and the image is phisically stored, but once I go to another page and try to return to the page where the image is stored it always shows the image that was showing before.

    I think that this is happening because the RadBinaryImage is using the Cache, which is very usefull since the image won't be changed very often, but I need to disabled the cache when a new image is loaded or try to reload the image.

    Here is a bit of Code:

    <telerik:RadBinaryImage runat="server" Width="740px" Height="600px" ResizeMode="Fit"
        ID="RadImageOrganizationChart" AlternateText="OrganizationChart" ImageUrl="Images/Chart.jpg"/>

    /// <summary>
    /// Loads the image before uploading it
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        RadImageOrganizationChart.Width = Unit.Pixel(800);
        RadImageOrganizationChart.Height = Unit.Pixel(600);
     
        using (Stream stream = e.File.InputStream)
        {
            byte[] imageData = new byte[stream.Length];
            stream.Read(imageData, 0, (int)stream.Length);
            RadImageOrganizationChart.DataValue = imageData;
        }
     
            if (AsyncUpload1.UploadedFiles.Count > 0)
            {
                UploadedFile file = AsyncUpload1.UploadedFiles[0];
                string fullPath = Server.MapPath("~/Images");
                string fileName = "Chart.jpg";
                file.SaveAs(Path.Combine(fullPath, fileName)); 
            }
     
    }

    Reply

  • Tsvetina Tsvetina admin's avatar

    Posted on Mar 10, 2011 (permalink)

    Hi Francisco,

    The RadBinaryImage control uses an internal http handler which streams the image from the binary source to the page in which it has to be visualized.The storage of the binary stream when transferred between the control itself and the handler is the HttpContext.Current.Cache object and the image is cached in the browser. Its default expiration time is 2 hours. This means that subsequent loads of the binary image are taken from the browser cache when using the same url for access.

    In order to reload the image and not take it from the cache, you can rebind or recreate the control in which the RadBinaryImage is nested.

    Regards,
    Tsvetina
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

    Reply

  • Francisco avatar

    Posted on Mar 10, 2011 (permalink)

    Hello Tsevetina,

    Thanks for your answer, this is something I found on the documentation, but I didn't understand what does "rebind or recreate the control in which the RadBinaryImage is nested" means. If my RadBinaryImage is merely in a form, does it mean I need to rebind the whole form?

    Kind Regards,

    Reply

  • Tsvetina Tsvetina admin's avatar

    Posted on Mar 15, 2011 (permalink)

    Hi Francisco,

    By default each time the DataValue of RadBinaryImage is changed, it caches the new value and generates a new unique url pointing to it. This means that the described behavior should not be happening.

    I would recommend you to first try removing this setting form your RadBinaryImage declaration:
    ImageUrl="Images/Chart.jpg"
    because it might be preventing the control from generating unique urls.

    If this does not help, please provide us with more details on how the issue is replicated (in what browser, are you returning by revisiting the link or using the back button, etc.) and we will investigate it further.

    Greetings,
    Tsvetina
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

    Reply

  • Francisco avatar

    Posted on Mar 15, 2011 (permalink)

    Hi Tsvetina,

    I already tried to reset the ImageUrl, with no sucess.

    I'm using a button to redirect to my previous page (Response.Redirect(...)), but if I do right click and reload the page the image reloads correctly.

    This is a strange behavior, am I doing something wrong?

    protected void RadButtonChart_Click(object sender, EventArgs e)
    {
        Response.Redirect("Chart.aspx");
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (RadImage != null)
            {
                RadImageChart.DataValue = null;
                RadImageChart.DataBind();
                RadImageChart.Visible = true;
                RadImageChart.ImageUrl = "Images/Chart.jpg";
     
            }
        }
    }
            protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
            {
                RadImageChart.Width = Unit.Pixel(800);
                RadImageChart.Height = Unit.Pixel(600);
     
                using (Stream stream = e.File.InputStream)
                {
                    byte[] imageData = new byte[stream.Length];
                    stream.Read(imageData, 0, (int)stream.Length);
                     RadImageChart.DataValue = imageData;
                }
                try
                {
                    if (AsyncUpload1.UploadedFiles.Count > 0)
                    {
                        UploadedFile file = AsyncUpload1.UploadedFiles[0];
                        string fullPath = Server.MapPath("~/Images");
                        string fileName = "Chart.jpg";
                        file.SaveAs(Path.Combine(fullPath, fileName));
                    }
                }
    }


    protected void RadButtonReturn_Click(object sender, EventArgs e)
    {
        RadImageChart.Visible = false;
        Response.Redirect("PreviousPage.aspx");           
    }

    Reply

  • Tsvetina Tsvetina admin's avatar

    Posted on Mar 18, 2011 (permalink)

    Hello Francisco,

    What Response.Redirect() does is an initial load of the target page (as if you have never loaded it before). Therefore, it is expected that the binary image control does not keep the last uploaded image. This also explains why the initial image is shown - it is assigned in the Page_Load event handler on initial load, which is hit when you are redirected back to the page.

    There would be a problem with the binary image control in case you were going back to the initial page using the browser Back button (because it does not redirect, it just loads the page from cache).

    Kind regards,
    Tsvetina
    the Telerik team

    Reply

  • FERNANDO avatar

    Posted on Mar 29, 2011 (permalink)

    I don't understand, because I'm saving the image to a path which is used to load the image in the Page_Load(), the image is saving succesfuly but I thought that in Page_Load the RadBinaryImage will read again the url and load the image.

    If this is not possible, how I can achieve to load an image in a RadBinaryImage and save it to a file, so it will be loaded again for the rest of the users?

    Kind Regards,

    Reply

  • Tsvetina Tsvetina admin's avatar

    Posted on Apr 1, 2011 (permalink)

    Hello Fernando,

    I am not sure if this is the same problem as the previously described. I would advise you to open a formal support ticket and send us a runable version of your code and let us know what do you expect it to do, so we can modify it where needed and provide you with a working solution.

    Best wishes,
    Tsvetina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > BinaryImage > Reloading Binary Image