Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

ToolTip / RadToolTipManager Client-side API

Mouseover the images below to view the customers from each country.


  • RadToolTipManager Client API

     

    This example demonstrates how you can create tooltips dynamically on the client by using the RadToolTipManager's client-side API and load their content by using a WebService.

    The page contains a few countries' images and a RadToolTipManager's contol which does not have them added in its TargetControls collection when the page initially loads. Each image's onmouseover event is hooked up and in its handler a tooltip is shown by using the manager's API:

    function showToolTip(element)
    {
           var tooltipManager = $find("<%=RadToolTipManager1.ClientID%>");

           //If the user hovers the image before the page has loaded, there is no manager created

           if (!tooltipManager) return;

          //Find the tooltip for this element if it has been created

          var tooltip = tooltipManager.getToolTipByElement(element);

         //Create a tooltip if no tooltip exists for such element

          if (!tooltip)
              {
                  tooltip = tooltipManager.createToolTip(element);

                 //Use the fact that the image was named after a country
                 //Extract the country name from the image, and set it as the value to be supplied to the web-service

                 var src = element.getAttribute("src", 2);
                 var country = src.substring (src.lastIndexOf("/") + 1, src.lastIndexOf(".")); 
                  tooltip.set_value(country);

              }
          setTimeout(function ()
                {
                      tooltip.show();
                }, 10);

    }  

    Note: The IgnoreAltAttribute property is introduced in the offical Q2 2010 release and it is not available in previous releases. When set to true, the tooltips ignore the alt attribute. The default value is false.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
        <style type="text/css">
            .country
            {
                margin: 4px;
                border: solid 1px #004759 !important;
            }
        </style>
    </head>
    <body class="BODY">
        <form id="Form1" method="post" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" />
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <script type="text/javascript">
            function showToolTip(element)
            {
                var tooltipManager = $find("<%= RadToolTipManager1.ClientID %>");

                //If the user hovers the image before the page has loaded, there is no manager created
                if (!tooltipManager) return;

                //Find the tooltip for this element if it has been created
                var tooltip = tooltipManager.getToolTipByElement(element);

                //Create a tooltip if no tooltip exists for such element
                if (!tooltip)
                {
                    tooltip = tooltipManager.createToolTip(element);

                    //Use the fact that the image was named after a country
                    //Extract the country name from the image, and set it as the value to be supplied to the web-service
                    var src = element.getAttribute("src", 2);
                    var country = src.substring(src.lastIndexOf("/") + 1, src.lastIndexOf("."));
                    tooltip.set_value(country);
                }

                //Let the tooltip's own show mechanism take over from here - execute the onmouseover just once
                element.onmouseover = null;

                //show the tooltip
                setTimeout(function ()
                {
                    tooltip.show();
                }, 10);
            }

        </script>
        <telerik:RadToolTipManager ID="RadToolTipManager1" Width="400px"
            HideEvent="ManualClose" RelativeTo="Element" Position="BottomCenter" runat="server"
            IgnoreAltAttribute="true">
            <WebServiceSettings Path="ToolTipWebService.asmx" Method="GetCustomersByCountryClientAPIExample" />
        </telerik:RadToolTipManager>
        <qsf:InformationBox ID="InformationBox1" runat="server" Width="810" Title="Mouseover the images below to view the customers from each country.">
        </qsf:InformationBox>
        <asp:Repeater runat="server" ID="itemsRepeater" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                <asp:Image ImageUrl='<%# Eval("Country", "~/Img/Northwind/Countries/Thumbs/{0}.gif") %>'
                    ID="Image" onmouseover='showToolTip(this);' runat="server" Width="150px" Height="150px"
                    class="country" alt="" />
            </ItemTemplate>
        </asp:Repeater>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: NorthwindConnectionString %>"
            SelectCommand="SELECT DISTINCT TOP 10 Country FROM Customers"></asp:SqlDataSource>
        <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451