Image or ImageButton without an ImageUrl

posted by Jon - 12:21 02/03/10

Recently we ran into a weird .NET nasty that took some time to track down and fix.

When testing an entry form, we were repeatedly being delivered an error on a completely separate page, we went through a lengthy process of commenting out multiple lines of code to try and find the problem. There was definitely no logical reason for the apparent redirect.

After confirming that none of the C# code behind for the .NET page was not causing the problem we moved on to looking at the HTML. The entry form page  had a number of stylised image buttons for form submission.  As the page was a work in progress the controls had not been completely styled at this point mainly lacking an ImageUrl property.

<asp:ImageButton runat="server" />

At first glance you would think nothing of it but this simple line is what was causing our issue.  But the rendered HTML...

<input src="" style="border-width:0px;" />

Notice the empty src attribute.  This oversight resulted in the browser requesting the folders default document as the image for the button, ultimately causing any code on the default page to run and display the error.

This little issue can also happen on image controls too.  So always make sure that any and every control derives from Image has its ImageUrl property set even if it is something like blank.gif.

There are no comments yet - why not be the first to leave one?

Leave a comment

CAPTCHA code image
Speak the codeChange the code