Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / ToolTip / Fine-tuning load on demand requests of RadToolTipManager

Fine-tuning load on demand requests of RadToolTipManager

Article Info

Rating: 1

Article information

 

 

 

Article relates to

 

 

 

 RadToolTip for ASP.NET AJAX

 

 

 

Created by

 

 

 

 Svetlina, Telerik

 

 

 

Last modified

Jan 20, 2012

Last modified by

Svetlina, Telerik

 


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.

1) 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).

2) 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:

//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);
                }
            }
        }

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, I 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) as shown in the following screenshot taken from the sample demo:







Note: The OnClientRequestStart event was added in Q2 2010 Beta (version 2010.2.623)  as documented here:

http://www.telerik.com/products/aspnet-ajax/whats-new/release-history/q2-2010-beta-version-2010-2-623.aspx

and it is not available in previous releases.

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.