Img src attribute getting replaced

I have a repeater that looks something like this:

<asp:Repeater>
<headertemplate>…</headertemplate>
<itemtemplate>
<tr>
<td>….</td>
<td><img
src=”../../images/myimg.gif” height=”16″ width=”16″ id=”img1″ runat=”server”
/></td>
<td>….</td>
</tr>
<footertemplate>….</footertemplate>
</asp:Repeater>

I
have an event handler on the ItemCreated event of the repeater, so that I can
check a value and put a javascript onclick event on the image if the value
passes the test.  This is all well and good, I view the page, check the
source and I see my onclick event attached to the image.  The problem is
that the src attribute has been changed.  It seems that when .net renders
the img, it removes one set of the parent path.  So the src on the page
looks like this:

<img src=”../images/myimg.gif” height=”16″ width=”16″
id=”img1″ runat=”server” />

So now my image has a broken link. Anyone know why,
WHY, would my image src attributes get changed??

I worked around the problem by removing the img element
completely, making the table cell a server control,  checking the value,
and then just writing the html literal string into the InnerHtml property
of the cell; this all works fine, but its annoying to have to waste time finding
this out.

 

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Enter my name (ben) in this box, so I know you're a human.

Comment: