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

Published Sunday, September 09, 2007 10:05 PM

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.

Comments

# Christopher Steen said on Monday, September 10, 2007 11:35 PM

Link Listing - September 10, 2007

# A Word about Link Blogs « Random Musings said on Wednesday, September 12, 2007 2:35 PM

Pingback from  A Word about Link Blogs &laquo; Random Musings

# Maciek said on Monday, September 17, 2007 6:19 AM

Thanks, I've been struggling with the same problem for some time now, even though I've seen this happening before.

# HyVong said on Tuesday, September 18, 2007 9:35 AM

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

# mark said on Tuesday, September 25, 2007 12:15 PM

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.

# Glavs Blog said on Thursday, October 11, 2007 1:45 AM

In a previous post , I mentioned an obscure ASP.NET issue that had me scratching my head for a while

# Bernal Schooley said on Thursday, October 11, 2007 9:56 AM

Bingo... I think I've been struggling with some variations on this in IE7. Not with img src but an iframe src. In the VS2008 debugger, I'd see the page load multiple copies of itself and the referenced javascript files. This caused some subtle issues with javascript scope and parent references. In any case, I found a work around without understanding the cause. You're article definately gives me something else to look at when I see it again. Thanks.

# Masse said on Thursday, October 25, 2007 2:28 PM

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

# Ali said on Monday, November 05, 2007 2:24 AM

I had different scenario but the cause was the same: src="".  Fixed the problem after reading your post. Thank you very much.

# Nuno Agapito said on Friday, November 30, 2007 10:22 PM

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

# email-filtering-services.com said on Friday, December 21, 2007 7:08 PM

We're immensely enthusiastic that you have stumbled upon our page dealing with employee privacy.

# karthik said on Thursday, February 14, 2008 3:41 AM

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

# Mike said on Thursday, February 28, 2008 3:49 PM

How did you go about debugging this?

# JRW said on Tuesday, April 15, 2008 12:16 PM

Thank you thank you thank you!

# Paranoia said on Thursday, May 08, 2008 4:25 AM

thx thx thx

i had this prb for months. NOW IS FINALY SOLVED

# Will said on Monday, June 16, 2008 12:00 PM

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

Leave a Comment

(required) 
(required) 
(optional)
(required)