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

Object reference not set in image handler

1 Answer 58 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Josep Bonet
Top achievements
Rank 1
Josep Bonet asked on 16 Apr 2010, 11:26 AM
Hello,

here is my problem: I've got two radbinaryimages and each one is in a wizardstep inside an asp.net wizard. In step one, the first binaryimage is displayed, but when I switch to page 2, the second one is empty and I get an "Object reference not set" in the processrequestinternalmethod of the radbinaryimagehandler.
If I look inside the cache, I can see the data from the visible image but not from the second one.

The sample belows reproduce the problem. Though it's not a wizard, it's the same problem.

Did I miss something?

Best regards

Laurent

ASPX:
<telerik:RadBinaryImage runat="server" Visible="true" ID="binaryImage1" /> 
<telerik:RadBinaryImage runat="server" Visible="false" ID="binaryImage2" /> 
<asp:Button runat="server" ID="btn" OnClick="btn_Click" /> 

CS:
 protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                byte[] img = File.ReadAllBytes(@"d:\mydocuments\My Pictures\IMG_2787.JPG"); 
                binaryImage1.DataValue = img; 
                binaryImage2.DataValue = img; 
            } 
        } 
protected void btn_Click(object sender, EventArgs e) 
        { 
            binaryImage1.Visible = !binaryImage1.Visible; 
            binaryImage2.Visible = !binaryImage2.Visible; 
        } 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 19 Apr 2010, 01:30 PM
Hello Josep,

The behavior you are experiencing is by design. It is caused by a performance optimization in which the binary data is stored in the cache as late as possible as in this case in control's render/prerender methods. However as you may know when visible is set to false, render/prerender methods will not be called, thus the logic to store the data in the cache is not executed. In order to workaround this you may consider setting initial visible value after prerender for example inside PreRenderComplete event.

protected override void OnPreRenderComplete(EventArgs e)
{
    base.OnPreRenderComplete(e);
    if (!IsPostBack)
    {
        binaryImage2.Visible = false;
    }               
}

Regards,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
BinaryImage
Asked by
Josep Bonet
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or