Adding a ToolTip to an Image (asp:image, img)

Yep this is one of the most simplest functionality that any developer in .Net framework would be looking for.

But why am I blogging about this then??? Okay most of you might have the answer to this one already and there are multiple ways to getting the following functionality in a web page. So the only reason that I am mentioning this issue here is that its simple as ABC, still some people don’t get it right.

In the good old days of ASP you just set the alt attribute of the <img>tag. And the image would show the text as a tooltip when you bring the mouse over it.

Now in ASP. NET while using the ASP .NET Server Controls you just set the Alternate Text attribute of the <asp:image> tag. See its simple as that.

Still if you go on and you are using a grid or a repeater for displaying the image its fine till you get to display the cells dynamically. For the dynamic controls I usually prefer using the HTML-Controls like most of the developers [System.We.UI.HTMLControls.HTMLImage], here you just need to set the alt attribute again.

Or you could use the Web Controls Image control [System.Web.UI.WebControls.Image], again just set the tool-tip by setting the ToolTip property for this control.

Happy Tool Tipping your images. ;P .

Author: dotnetolympians

I am an IT Professional and a Microsoft Evangelist working in the field of web applications. I love to program and spend most of my time online in disscusion groups and forums. [rockyou id=63046560]

9 thoughts on “Adding a ToolTip to an Image (asp:image, img)”

  1. I was eagerly looking for tooltip to HTMLImage and this article really helped me..

    Thanks & Regards,
    Eclat.

  2. David is correct, the alt attribute should not be used for defining an image tooltip.

    In older versions of Internet Explorer (pre 8), the alt attribute did determine what would display as a tooltip. Microsoft got it wrong!! Other browsers such as Firefox and Mozilla got it right!

    The title attribute should be used to define image tooltips.

    For all those developers out there with hundreds of img tags that only contain alt attributes, there is a Windows application called Alt&Title that will automatically add title attributes to applicable tags if an alt attribute already exists.

    Alt&Title saved me many hours of work. Give it a go.

    Here is a link to the Web page promoting it…

    http://www.flysoftware.com/products/altandtitle/overview.asp

  3. I am not sure where you are getting your information,
    but good topic. I needs to spend some time learning much
    more or understanding more. Thanks for magnificent information
    I was looking for this info for my mission.

Leave a comment