Obscure ASP.NET Problem - AJAX Control Toolkit, CollapsiblePanelExtender, Image controls pages loading more than once....

Had an issue on a current project where a page was being loaded twice for each request, although it was a little different for each browser. Under IE, this particular page was loaded, then the 'Default.aspx' page in the same directory was loaded. In Firefox, the same page was loaded twice. This was verified by simply placing breakpoints in the Page_Load events and watching it get hit twice, in addition to seeing this via the NET monitor in Firebug (the Firefox addin).

It was causing performance issues as well as weirdness regarding page state, as you can imagine. So in I went, thinking it should be relatively easy to debug. Turns out it was quite obscure and took more time than I had originally anticipated.

Scenario:

This page was using a CollapsiblePanelExtender from the AJAX Control toolkit to display a drop menu in the page. The CollapsiblePanelExtender had a declaration like the following:

<Some properties removed for brevity>

Note the use of the CollapsedImage and ExpandedImage properties. These tell the extender what images to display when the control is in a collapsed and expanded state. We also used the ImageControlID property to point to an <asp:Image control for the extender to manipulate with the respective images. Its declaration looked like this:

And therein was the cause of the problem! The page itself looked as though it worked fine. The CollapsiblePanelExtender changed the image accordingly and it looked good. However, the <asp:Image control did not originally have any ImageUrl property specified to an initial image (even though the CollapsiblePanelExtender was dynamically setting it). This rendered out to the page like this:

Now you see it right? The src="" part of the tag. This caused IE to make a request against the /WebDirectory/ and thus it was getting the default.aspx document in that directory. It caused Firefox to request exactly the same again. So 2 requests for the 1 page request. Obviously to solve it, we just specified the original image to be displayed as part of the image control like so:

Problem solved!

Now in general, it might be obvious that an <asp:Image control might render out this way, and cause such an issue but the fact that the CollapsiblePanelExtender was dynamically setting this, and making it look like it was working fine, really threw me. It took some creative debugging to drill down and find this particular issue out, which I may highlight in the next post.

15 Comments

  • I acutally have had this issue last month too. I found out the issue and was able to resolve it then, but I didn't have time to investigate on why the image would cause such an issue. Thanks

  • I have a similar problem but the image is displayed inside A Telerik grid. If I put an image in anything but the last table in a hierachy, I get 2 post backs, which muck up the page state (I have code inside !Ispostback which is subsequently being executed where it shouldnt be)
    If I put any other controls (buttons, chckboxex, etc) its fine
    I tried the example workaround above but it didnt work.

  • Solved my problem. Luckily i found this post straight away. Thanks a million.

  • It took me 5 hours to discover the problem and when I correct the bug, 5 minutes later I find this article...

    Don't helped with the problem itself but helped to understand the reason of the "bug".

    Thanks

  • the image url property do not allow me to select image in different directory. that not even display the image file even though the computer has picture file

  • thx thx thx
    i had this prb for months. NOW IS FINALY SOLVED

  • Thank you, I would've been on this one for ages, as would've a lot of other people by the look of it! :-)

  • Thanks, had the same problem but for me it was worse...I'm using extensionless URL's. My instance of src="" was sitting in some ajax enabled stuff in my footer, so every single page request was causing a second page request with the url being the PARENT folder of the initial url!

    Cheers!

  • I ran into a very similar problem. Instead the culprit being an empty src tag, it was using assigning String.Empty to the background-image style. The resulting html was being rendered as background-image: url(); Doh!


    if (TextBox1.Text.Equals(String.Empty))
    TextBox1.Style["background-image"] = "url('/Images/dtb_watermark.GIF')";
    else
    TextBox1.Style["background-image"] = String.Empty;

    Thanks for the help, this one was driving me crazy!!

    52

  • OMG I never would have figured this out. Thanks!

  • Thanks for your article, i got the same issue and didn't know reason. now, i have solved it.

  • I'm running into this bug right now as well. Is the culprit here IE? Why is it reaching out to the server when SRC is blank? Is this a known bug?

  • Thanks a lot! I think I would have spent even more time on this if I hadn't found your post.

  • Had exactly the same issue - thx a lot, you saved me a lot of time and frustration!

  • Thanks for sharing. Saved me a lot of time, too.

Comments have been disabled for this content.