views:

773

answers:

4

Hi, I have a problem with how ASP.Net generates the img tag. I have a server control like this: ,

asp:Image runat="server" ID="someWarning" ImageUrl="~/images/warning.gif" AlternateText="Warning" />

I expect it to generate this:
img id="ctl00_ContentPlaceHolder1_ctl00_someWarning" src="../images/warning.gif" />
but instead it generates this:
img alt="" src="/Image.ashx;img=%2fimages%2fwarning.gif"

This give me errors when I execute the following js: document.getElementById('ctl00_ContentPlaceHolder1_someWarning')

Any idea why it won't generate the expected html? Thanks.

+1  A: 

Looks like it's trying to use a custom handler (ashx) to deliver the image. Do you have any additional modules that may be overriding the default behaviour of the asp:Image?

Your JavaScript won't work because the image tag has not been given an ID in the HTML that was generated.

Ady
A: 

The weird thing is that it won't do this for all images. Only for a few ones.

Adrian Magdas
Have you tried creating a new blank project with no additional modules? Does this reproduce your problem?
Ady
Probably a silly question - but are your IDs unique?
stusmith
A: 

You can get the actual ID that is generated by using ClientID. I use this to get the ID of a control for use in JavaScript using syntax similar to the following:

document.getElementById('<%=ddlCountry.ClientID%>').style.display  = "block";

However you can also use it in your code-behind to get the same thing.

AaronS
A: 

It was using an custom ashx handler.

Adrian Magdas