<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!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">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <script type="text/javascript">
            var i = 0;
            var endOfItems = false;
            
            function OnClientItemsRequesting(sender, eventArgs)
            {
                if (endOfItems)
                {
                    eventArgs.set_cancel(true);
                    
                    return;
                }
                
                var context = eventArgs.get_context();

                context["ItemOffset"] = i + "";
                
                i = i + 20;
                
                sender.clearItems();
                sender._itemData = null; 
            }
            
            function OnClientItemsRequested(sender, eventArgs)
            {   
                var messageElement = sender.get_moreResultsBoxMessageElement();
                
                var messageText = messageElement.innerHTML;
                
                var regExp = new RegExp("-<B>[0-9]+");
                
                var currentItemsText = regExp.exec(messageText);
                
                currentItemsText = currentItemsText[0].replace("-<B>", "");
                
                regExp.compile("of <B>[0-9]+");
                
                var totalItemsText = regExp.exec(messageText);
                
                totalItemsText = totalItemsText[0].replace("of <B>", "");
                
                if (currentItemsText == totalItemsText)
                {
                    endOfItems = true;
                }
            }
            
            function OnClientKeyPressing()
            {
                i = 0;
                
                endOfItems = false;
            }
        </script>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <telerik:RadComboBox
                ID="RadComboBox1"
                Runat="server"
                Height="140px"
                Width="350px"                             
                EnableLoadOnDemand="True"
                Skin="Vista"
                AllowCustomText="True"                            
                ShowMoreResultsBox="True"
                ItemRequestTimeout="500"
                OnItemsRequested="RadComboBox1_ItemsRequested"
                OnClientKeyPressing="OnClientKeyPressing"
                OnClientItemsRequesting="OnClientItemsRequesting"
                OnClientItemsRequested="OnClientItemsRequested">
            </telerik:RadComboBox>
        </div>
    </form>
</body>
</html>
