I am trying to move away from server image tags (don't need a postback) and
am having a real difficult time getting the image to show properly.
The following code is in a repeater:
<table>
<tr>
<td>
<asp:ImageButton Height="16px"
ID="ImageLeft" ImageUrl="~/Images/music-32x32.png"
AlternateText='<%# Eval("FileName")%>'
runat="server" />
</td>
</tr>
<tr>
<td>
<img alt="" id="ImageLeftPlus"
src="~/Images/music-32x32-plus.png" height="16px" />
<asp:ImageButton Height="16px"
ID="ImageLeftPlus1" ImageUrl="~/Images/music-32x32-plus.png"
AlternateText='<%# Eval("FileName")%>'
runat="server" />
</td>
</tr>
</table>
Note that image src or ImageUrl are the same for the two buttons in the
bottom tr.
Using the IE Developer Toolbar I can see the following:
The asp:ImageButton generates the follow URL:
http://localhost:57217/MusicSite/Images/music-32x32-plus.png
The img generates the following URL:
http://localhost:57217/MusicSite/~/Images/music-32x32-plus.png
WTF???
I can't make heads nor tails of what is going on. What would the correct
src for the <img> tag be or is there a way of have the imagebutton not make
postbacks??
Thanks
Lloyd Sheen
Mark Rae [MVP] - 31 Oct 2007 01:08 GMT
> The asp:ImageButton generates the follow URL:
> http://localhost:57217/MusicSite/Images/music-32x32-plus.png
[quoted text clipped - 3 lines]
>
> I can't make heads nor tails of what is going on.
Only web controls e.g. asp:ImageButton understand the tilde shortcut - HTML
controls e.g. <img.../> don't, unless you include runat="server"...
> is there a way of have the imagebutton not make postbacks??
Why don't you just use an <asp:Image /> control...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Lloyd Sheen - 31 Oct 2007 14:48 GMT
>> The asp:ImageButton generates the follow URL:
>> http://localhost:57217/MusicSite/Images/music-32x32-plus.png
[quoted text clipped - 10 lines]
>
> Why don't you just use an <asp:Image /> control...?
Thanks went the asp:Image route. Works great. Not sure why I was using the
ImageButton
Lloyd Sheen
Peter Bromberg [C# MVP] - 31 Oct 2007 01:44 GMT
The "img" Html control is not an ASP.NET Server-side control, it's a plain
old HTML control. Therefore, the "~" - which would only be processed at the
server, is meaningless, hence your problem. You could either put a
runat="server' attribute on it, or simply use the ASP.NET <asp:Image ...>
control.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
> I am trying to move away from server image tags (don't need a postback) and
> am having a real difficult time getting the image to show properly.
[quoted text clipped - 41 lines]
> Thanks
> Lloyd Sheen