Load On Demand functionality not Loading on Demand.

15 posts, 0 answers
  1. Ben
    Ben avatar
    2 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2012 Link to this post

    Hi everyone, I'm working with the RadRotator and have followed the LoadOnDemand example to set up a functional rotator control that we could use on our web site. I see that the backend code of the web service is returning viewable images when viewed through an image visualizer in the VS2010 debugger. But after returning the an array of  RadRotatorItemData I get the error message:

    RadRotator items request failed : Exception=Object reference not set to an instance of an object.

    Any idea what might be going wrong?

    Also let me know if showing code would be helpful in getting to the bottom of this issue.

    Thanks for your help!

  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 03 Aug 2012 Link to this post

    Hi Ben,

    I would suggest checking if NullReferenceException is thrown at some point in the execution of the web service code, as this is the usual cause for the message you received. In order to provide a concrete solution I will need to run your code on my end, which requires a fully runnable sample that includes data source and additional references assemblies if such are used in your project.

    Regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 16 Nov 2012 Link to this post

    HI,

    With load on demand RadRotator, I would like to refresh data  once Rotator  completes displaying all items from a data set .
    How can I do this?

    Thanks,
    Prava
  5. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 19 Nov 2012 Link to this post

    Hello Prava,

    The client-side event of RadRotator OnClientItemShown is fired when an item of the rotator control is shown. You can use this event to detect the index of the currently loaded item. When the last item is reached, you can initiate an AJAX request that will reset the RadRotator so that the loading of its items can start again.

    Kind regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 19 Nov 2012 Link to this post

    Hi Slav,

    I would like to rebind RadRotator with  fresh dataset,  I am binding it to webservice. What will be the code to reset RadRotator?

    Thanks,
    Prava
  7. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 19 Nov 2012 Link to this post

    Hi,
    I added following code and I found that "OnClientItemShown"  event did not fire after displaying 10th item, as the scrollview had already displayed all 17 items from datasource. How can I know , it displayed all items, I went through client api and could not find any method or properties that will help me .


     function OnScrollItemShown(sender, eventArgs) {
                var rotator = $find("<%=RadRotatorHorizontal.ClientID %>")
                var totalItems = $("ul.rrItemsList > li").length;
                var currentItemIndex = eventArgs.get_item().get_index();


                if (currentItemIndex >= totalItems) {
                    alert(currentItemIndex);
                    $('#RadRotatorHorizontal').repaint();
                }


            }

    Thanks,
    Prava
  8. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 20 Nov 2012 Link to this post

    Hi Prava,

    Since the RadRotator loads its items on demand, the control is not aware how many items will added. This is why you need to hardcode the number of the last index. If there is more than one item, displayed in the viewport of the rotator, you should check for the index of the first one that is shown in the last view.  After you detect that all items are displayed, you can use the RadAjaxManager to set the rotator as updated control and initiate an AJAX request.

    I have attached a sample that demonstrates the approach, described above. Please use it as a reference for implementing the desired functionality.

    All the best,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 20 Nov 2012 Link to this post

    Hi Slav,

    Thank you very much for  providing a sample. Unfortunately, I cannot hard code a  value in "OnClientItemShown"  event because I don't know how many messages will be dis[played in view port. Depending on the length of messages, there might be only one long message or  5 or more  short messages. Is there any client side property that I can use to count number of messages in view port?


      function OnClientItemShown(sender, args) {
                var rotator = $find("<%=RadRotatorHorizontal.ClientID %>")
                var totalItems = $("ul.rrItemsList > li").length;

                if (args.get_item().get_index() == totalItems - 1) {
                    $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest("resetRotator");
                }
            }
    Thanks,
    Prava
  10. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 20 Nov 2012 Link to this post

    Hi Slav,

    Thank you very much for  providing a sample. Unfortunately, I cannot hard code a  value in "OnClientItemShown"  event because I don't know how many messages will be displayed in view port. Depending on the length of messages, there might be only one long message or  5 or more  short messages. Is there any client side property that I can use to count number of messages in view port?

    Once rotator  displays last message(we do not know how many records are there), it should go and reset its datasource.
    The new datasource may have more/less records and the record itself may be modified and this should be reflected in the next round.

      function OnClientItemShown(sender, args) {
                var rotator = $find("<%=RadRotatorHorizontal.ClientID %>")
                var totalItems = $("ul.rrItemsList > li").length;

                if (args.get_item().get_index() == totalItems - 1) {
                    $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest("resetRotator");
                }
            }
    Thanks,
    Prava
  11. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 23 Nov 2012 Link to this post

    Hello Prava,

    Note that all items of RadRotator should have the same width and height as described in this help article. Configuring the rotator otherwise could result in an unexpected behavior.

    Since the items are loaded on demand, their final count cannot be retrieved. I can suggest an alternative approach that can help you implement the desired functionality. The rotator control supports client-side methods for adding and removing items, which is demonstrated in this online demo. You can load the data from your web service separately and then use the method addRotatorItem to populate the rotator. This way you will have more control over the process of loading items in the rotator.

    Kind regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  12. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 26 Nov 2012 Link to this post

    Hi Slav,

    I will try to implement your suggestions. In the mean time I just want to confirm that RadRotator does not  have a property that gives me the  number of items in viewport?

    Thanks,
    Prava
  13. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 29 Nov 2012 Link to this post

    Hi Prava,

    Indeed, there is no property that gets the number of RadRotator items in the control's view port. You can determine their count using the values of the properties Width, ItemWidth (if the rotator is horizontally oriented) or Height, ItemHeight (if the rotator is vertically oriented) as described in the help article, linked in my previous post. Having items with different size is not a supported scenario and will most likely lead to inconsistent rotator behavior.

    Greetings,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  14. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 27 Dec 2012 Link to this post

    Hi,

    Since my RadRotator is  scrolling the viewport instead of scrollItem, I do not know when it reached  the end of datasource.
    To force it to refresh, I would like to call "updateRotator" at an interval of 40Sec. 

    Following code doesnot refresh it, am I missing anything here?



      function updateRotator() {
                setTimeout(function () {
                    var rotator = $find("<%=RadRotatorHorizontal.ClientID %>");
                   $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest("resetRotator");
                    updateRotator();
                 },40000)

            }




     <telerik:RadRotator ID="RadRotatorHorizontal" runat="server"  CssClass="positionCenter"    Height="24px"  
                               ItemHeight="24"  Width="100%"  PauseOnMouseOver="true"   ScrollDirection="Left"   RotatorType="FromCode"   FrameDuration="3000"   EnableRandomOrder="false"  > 
                                            <ItemTemplate>  
                                                   <div class="itemTemplate"   >
                                                             <%# Container.DataItem %> 
                                                    </div>
                                            </ItemTemplate>
                                            <WebServiceSettings Path="WorkforceServices/WorkforceDataService.asmx" Method="GetScrollMessageRotatorData"   ></WebServiceSettings>
                                            
                                </telerik:RadRotator>
         





    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
            EnablePageHeadUpdate="False">
            <AjaxSettings>
                            <telerik:AjaxSetting AjaxControlID="Timer1" >
                                <UpdatedControls>
                                       <telerik:AjaxUpdatedControl ControlID   = "RadRotatorHorizontal"     />



    Thanks,
    Prava

  15. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 28 Dec 2012 Link to this post

    Hi Slav,
    I gave fixed item width to RadRotator and with this change "args.get_item().get_index() " always return index = "0". Since it always returns" 0", it does not send ajax request to refresh rotator.


       function OnClientItemShown(sender, args) {
                var rotator = $find("<%=RadRotatorHorizontal.ClientID %>")
                var totalItems = $("ul.rrItemsList > li").length;
                if (args.get_item().get_index() == totalItems - 1)
                    $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest("resetRotator");
         
      }


    Thanks,
    Prava
  16. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 02 Jan 2013 Link to this post

    Hello Prava,

    In your code sample you have configured the RadRotator property RotatorType to FromCode, which is used when implementing a custom rotation. Usually the client-side method showNext is utilized for sliding the items, as you can check in this online demo.  Your sample, however, does not include the code for sliding the rotator items so it is not enough for me to determine why every time the same index is returned. Please try modifying the project I attached previously to match your case or if this is not possible, send a fully runnable sample that isolates the scenario.

    Note that the number of li elements in the rotator will not give you the total number of items as new li elements will be inserted when the control request data from the web service. The best approach for dynamically loading the rotator items and detecting the last of them is retrieving the data from the web service separately and using the client-side API of RadRotator to add them as I have suggested previously. 

    Greetings,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017