Creating Dynamic ToolTip Using RadControls and JavaScript

RadToolTip

 
RadToolTip is a context-sensitive tool for displaying rich content, detailed information, overlaid forms, or just about anything that should appear over a given element. This can display rich content, including (but not limited to) text and images, but also some interactive forms with standard ASP.NET and user controls.
 
Basic Properties
 
The basic properties are:
  1. TargetControl ID: It specifies the ID of the element on which the tooltip should appear to the client.
  2. IsClient ID: When set to True the element is pure HTML and not a server control.
  3. On Ajax update: Event to supply the content of tooltips generated by RadToolTipManager.
  4. rad_Ajaxupdate: This function is fired when the targeted control is triggered and the function is written in a .vb file.
  5. Show Events: This property helps to set the event on which the tooltip must be shown.
Key Features
 
The key features are:
  • Display HTML and ASP.NET
  • Add to a Single or Multiple Elements
  • Load on Demand
  • Full Control over Tooltip Position
  • Show on Event
  • Close on Click
  • Mouse Trailing
  • Sticky Tooltips
  • Show Delay and AutoClose Delays
  • Animation effects
  • Microsoft AJAX Update Panel in RadToolTip
  • Content scrolling
  • Advanced Skinning
Example
 
First create a web page where you want to apply the tooltip.
 
Here I am creating a div and inside it, I insert five images and pass a JavaScript function name with the handle of the tooltip binding and all that.
  1. <div>  
  2.        <img id="image1" src="1.jpg" onmouseover="showToolTip(this);" /><br />  
  3.        <img id="image2" src="2.jpg" onmouseover="showToolTip(this);" /><br />  
  4.        <img id="image3" src="3.jpg" onmouseover="showToolTip(this);" /><br />  
  5.        <img id="image4" src="4.jpg" onmouseover="showToolTip(this);" /><br />  
  6.        <img id="image5" src="5.jpg" onmouseover="showToolTip(this);" />  
  7. </div> 
 
DynamicTooltip1.jpg
 
Now add a scriptmanager and RadToolTip and provide the required properties, whatever you need.
  1. <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>  
  2.         <telerik:RadToolTip ID="RadToolTip1" runat="server"  
  3.             RelativeTo="Element" Position="MiddleRight" Width="150px" ShowEvent="FromCode"  
  4.             HideEvent="LeaveTargetAndToolTip">  
  5.         </telerik:RadToolTip> 
Note: To work with a RadControl you need to first register the control as I do at the top of the page.
 
Now for the JavaScript function, as in the following:
  1. <script type="text/javascript">  
  2.             function showToolTip(obj) {  
  3.                 var radToolTip = null;  
  4.                 switch (obj.id) {  
  5.                     case 'image1':  
  6.                         radToolTip = $find("<%= RadToolTip1.ClientID %>");  
  7.                         radToolTip.set_targetControl(obj);  
  8.                         radToolTip.set_text("This is Cat ");  
  9.                         break;  
  10.                     case 'image2':  
  11.                         radToolTip = $find("<%= RadToolTip1.ClientID %>");  
  12.                         radToolTip.set_targetControl(obj);  
  13.                         radToolTip.set_text("This is Tiger");  
  14.                         break;  
  15.                     case 'image3':  
  16.                         radToolTip = $find("<%= RadToolTip1.ClientID %>");  
  17.                         radToolTip.set_targetControl(obj);  
  18.                         radToolTip.set_text("This is Dog");  
  19.                         break;  
  20.                     case 'image4':  
  21.                         radToolTip = $find("<%= RadToolTip1.ClientID %>");  
  22.                         radToolTip.set_targetControl(obj);  
  23.                         radToolTip.set_text("This is Penguin");  
  24.                         break;  
  25.                     case 'image5':  
  26.                         radToolTip = $find("<%= RadToolTip1.ClientID %>");  
  27.                         radToolTip.set_targetControl(obj);  
  28.                         radToolTip.set_text("This is Spider");  
  29.                         break;  
  30.                 }  
  31.                 setTimeout(function () {  
  32.                     radToolTip.show();  
  33.                 }, 5);  
  34.             }  
  35.         </script> 
In the JavaScript function above I am using a switch/case. Using the case I simply set the text to a particular image.
 
Now test the page, just run your page and when you hover your mouse over an image you will see the tooltip showing different text for each of the images.
 
DynamicTooltip2.jpg
 
DynamicTooltip3.jpg
 
Thanks