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

Invalid JSON primitive

5 Answers 287 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
ian lipsky
Top achievements
Rank 1
ian lipsky asked on 22 Feb 2012, 07:17 AM
Hello,
I'm trying to implement an infinite scrolling method. I'm trying to use the method described on this page:http://www.fieg.nl/infinite-ajax-scroll-a-jquery-plugin That method basically takes your pagination links and uses those to get the next batch of records when the user scrolls to the bottom of the page. I seem to be running into some sort of conflict with this and the radrating control. With the radrating control enabled on the page, i get the above error (Invalid JSON primitive) when ever i cause a post back. It can either be a postback caused by a .net control set to autopostback=true, or it just be a simple html submit button. Also, the rad rating controls stop working once you go past the first page of records. 

If i remove the rad rating control from the page, then the scrolling and doing a postback work as expected. 

The rating control is inside of a .net listview. The only code on page load which that I have that deals with the rating control is this:

protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
    if (e.Item.ItemType == ListViewItemType.DataItem )
    {
        ListViewDataItem myDataItem = (ListViewDataItem)e.Item;
 
        System.Web.UI.WebControls.DataKey myKey = this.ListView1.DataKeys[myDataItem.DisplayIndex];
 
        Decimal rating = (Decimal)ListView1.DataKeys[myDataItem.DisplayIndex]["Rating"];
        string id = ListView1.DataKeys[myDataItem.DisplayIndex]["ID"].ToString();
 
        RadRating myRad = (RadRating)e.Item.FindControl("RadRating1");
        myRad.Value = rating;
        myRad.Attributes["GameId"] = id;
 
    }
}
 
And this code seems to work correctly as i scroll down the page - it's getting fired every time you scroll to the bottom of the page and it appears to be passing correct values. However, my rating_changed event never fires once you scroll past the first page.

I have an idea as to why this is happening. Since this infinite scroll works by essentially loading the next page and then appending just the specific html involved with the page, i think there's 2 errors this causes.

1. The control ID's are getting duplicated because as far as the .net page knows, it's loading up a new page. So if the last ID on the first page was radrating1_5, when i load the next page, it has no reason not to re-use that ID since it think it's a new page.

2. Any script associated with these controls isn't being properly loaded since it's not included inside the content tags where the page data lives. And that infinite scroll only loads what's inside the content container div.

So i have a few questions

1. anyone know of an infinite scrolling plugin that'll work on a page with multiple rad rating controls?
2. if not, would there be any problem if i set the control id's in codebehind with each page load so that i can ensure each control has a unique ID?
3. Is there any way to control where all the javascript gets rendered for each control? Because I have a feeling any infinite scroll plugin will have a problem with the jscript code loading outside of where the content loads.

5 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 24 Feb 2012, 02:09 PM
Hello Ian,

Can you confirm whether the problem replicates with other script controls - a different RadControl or for example a control from the AjaxControlToolkit. If you experience similar problems, then this plugin is not implemented to work with script controls that are created on the server.

If this is the case, you can instead set an initial page size to the listview, then when the scroll reaches the bottom of the container, make an AJAX call to the server, increase the page size of the listview by a desired number of items and rebind it. And so, you will again get the infinite scrolling experience.
You can see how we have done it with RadGrid here:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/virtualscrollpaging/defaultcs.aspx (see the second grid)

Regards,
Tsvetina
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
ian lipsky
Top achievements
Rank 1
answered on 25 Feb 2012, 12:36 AM
thank you very much for the reply.  I will take a look at this in a little bit and see if i can make this work for my needs - sounds like it will.
0
ian lipsky
Top achievements
Rank 1
answered on 26 Feb 2012, 07:38 AM
I just had a chance to look at the demo. Would i be able to do this but without requiring a scroll bar on the grid (or list) and just use the scrolling of the page itself to load more content?
0
Tsvetina
Telerik team
answered on 27 Feb 2012, 04:30 PM
Hello Ian,

It might be easier if you wrap the control in a scrollable div, so you can get its client height and compare it to the current scroll position to indicate when you have reached the bottom of the current scroll area.
Anyway, the above is what matters - to know when you have reached the bottom of the scroll, as long as you can indicate this, you are good to go with this approach.

Greetings,
Tsvetina
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
Manesh
Top achievements
Rank 2
answered on 08 May 2012, 10:37 AM
Hi friends, i'm having 2 issue or problems please help me out
1. When i'm selecting a row in a grid i'm getting an error as " Invalid JSON primitive: "
2. I'm having one combo box and i'm selecting one of the item in it then, after selecting the combo box is loosing its focus and the cursor is not blinking in it

please help me out
Tags
Ajax
Asked by
ian lipsky
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
ian lipsky
Top achievements
Rank 1
Manesh
Top achievements
Rank 2
Share this question
or