This is a migrated thread and some comments may be shown as answers.

Load On Demand functionality not Loading on Demand.

14 Answers 123 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 01 Aug 2012, 12:01 AM
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!

14 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 03 Aug 2012, 10:41 AM
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.
0
Prava kafle
Top achievements
Rank 1
answered on 16 Nov 2012, 06:02 PM
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
0
Slav
Telerik team
answered on 19 Nov 2012, 03:59 PM
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.
0
Prava kafle
Top achievements
Rank 1
answered on 19 Nov 2012, 05:08 PM
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
0
Prava kafle
Top achievements
Rank 1
answered on 19 Nov 2012, 06:32 PM
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
0
Slav
Telerik team
answered on 20 Nov 2012, 04:32 PM
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.
0
Prava kafle
Top achievements
Rank 1
answered on 20 Nov 2012, 07:23 PM
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
0
Prava kafle
Top achievements
Rank 1
answered on 20 Nov 2012, 07:34 PM
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
0
Slav
Telerik team
answered on 23 Nov 2012, 05:07 PM
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.
0
Prava kafle
Top achievements
Rank 1
answered on 26 Nov 2012, 01:31 PM
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
0
Slav
Telerik team
answered on 29 Nov 2012, 09:47 AM
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.
0
Prava kafle
Top achievements
Rank 1
answered on 27 Dec 2012, 06:07 PM
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

0
Prava kafle
Top achievements
Rank 1
answered on 28 Dec 2012, 06:03 PM
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
0
Slav
Telerik team
answered on 02 Jan 2013, 10:50 AM
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.
Tags
Rotator
Asked by
Ben
Top achievements
Rank 1
Answers by
Slav
Telerik team
Prava kafle
Top achievements
Rank 1
Share this question
or