Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Help with img tag and VS 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Sheen - 31 Oct 2007 00:45 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.