asp.net - How to show a tool tip on an Image

Set or change Image ToolTip programmatically
Image is an asp.net web server control which allow us to display an image in web page. this Image web server control allow us to work with images in server code. Image server control have a built in property to display tooltip on Image control programmatically at run time.

Image ToolTip property get or set the text displayed when the mouse pointer hovers over the Image control. so, by using this ToolTip property we can show tooltip on Image control. this property value type is System.String. this property allow us to show extra information about specified image when user mouse hover over the image.

the following asp.net c# example code demonstrate us how can we set or change the Image control tooltip programmatically at run time in an asp.net application.
ImageToolTip.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Image1.ToolTip = "Test ToolTip";

    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Image1.ToolTip = "Another ToolTip";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change Image tool tip (ToolTip) programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Image Example: Change ToolTip</h2>
        <asp:Image 
             ID="Image1" 
             runat="server"
             ImageUrl="~/Images/Fish8.jpg"
             BorderColor="DarkBlue"
             BorderWidth="3"
             BorderStyle="Outset"
             />
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DeepPink"
             Text="Set Image ToolTip"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="DeepPink"
             Text="Change Image ToolTip"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>








Related asp.net examples