New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Fine-tuning load on demand requests of RadToolTipManager

HOW-TO

Fine-tune the load on demand requests initiated by RadToolTipManager

SOLUTION

In general, to load content on demand means that it should be loaded only when needed and this technique is commonly used to avoid loading of resources and slowing of performance when this is not actually necessary. The RadToolTipManager control provides two manners to load content on demand - by using a WebService and by using an AJAX request. However, since not all scenarios require a "fresh" data after it has been once loaded, the RadToolTipManager provides an event which can not only help you use cached data but also implement other more complex scenarios such as getting new content only at specific condition (e.g twice a day, based on the user role, integration with a timer control, etc). The event in question is called OnClientRequestStart and it is a cancelable event which gets fired just before the request for loading content starts. In this manner you can use a flag which determines whether a new request should be actually done and this helps you to better control the requests and skip such which are not needed.

Usage with WebService

In this case, to stop a new request and to keep the old, cached content you should simply call args.set_cancel(true).

### Usage with AJAX

This case is a little bit more complex due to control specifics, e.g the fact that all the tooltips generated by RadToolTipManager share the same update panel and it is moved in the DOM. That is why after you have canceled the event you should additionally reset the current contentElement as shown below:

<script>
//flag variable which represents your condition
var flag = true;
        function OnClientRequestStart(sender, args)
        {
            var currentToolTip = Telerik.Web.UI.RadToolTip.getCurrent();
            var contentElement = currentToolTip.get_contentElement();
            if (flag)
            {
                args.set_cancel(true);
                //the content element is null only before first show; in general //we should always have some content before cancelling subsequent request //because of the first request; 
                if(contentElement)
                {
                   currentToolTip.set_contentElement(contentElement);
                }
            }
        }
</script>

Note, that the sender is RadToolTipManager because it supports load on demand requests and the separate tooltip doesn't. The tooltip which is being shown is the currently active one and it can be referenced by using the static getCurrent method.

In order to demonstrate the above explained solutions, we prepared a simple demo which caches the content after the first load on demand. The demo contains 4 cases - WebService tooltip with and without cached content and AJAX tooltip with and without cached content . The visual indicator of the requests is a label which shows the time (when cached content is used it does not change over time).

In this article