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

Invalid JSON Primitive

4 Answers 149 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 09 Jun 2008, 12:51 AM
Hello,

I am trying to refresh a treeview when I close a rad window... to do that, I've tried using this code in the onclose event:

        function RefreshTree() {
            __doPostBack('treeStructure', 'RefreshTreeStructure');
        }

In the .vb file I've got this...

    Protected Sub treeStructure_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles treeStructure.Load
        'If Me.IsPostBack Then
        '    Dim eventArg As String = Request("__EVENTARGUMENT")
        '    If eventArg = "RefreshTreeStructure" Then
        '        FillStructureTree(Me.cboSection.SelectedValue)
        '    End If
        'End If
    End Sub

the items are commented out as a part of me playing around with things - commented or not, I am getting this error:

Invalid JSON Primitive: RefreshTreeStructure

I am using context menus in the treeview and have a RadAjaxManager on the page that is controlling the treeview as well.

Any thoughts?

Thanks,

Mike

4 Answers, 1 is accepted

Sort by
0
Accepted
Simon
Telerik team
answered on 11 Jun 2008, 01:05 PM
Hi Mike,

I suggest you replace the first argument of the __doPostBack function with an empty string ("") if you do not need it on the server. In case you need it, I suggest you replace it with another identifier for the TreeView, different from its ID, like 'rt1' for example.

The problem is caused by this first argument: the TreeView on the page recognizes this postback as directed to it (from the first argument) and tries to parse the second argument which produces the error.

Sincerely yours,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 16 Jun 2008, 07:41 AM
Hi Simon,

Sorry for the delay in responding - thank you... looks great.

Mike
0
Ben Hobgood
Top achievements
Rank 1
answered on 12 Nov 2020, 05:50 PM

This post is old but we solved it by clearing the divs you load via ajax before postback, thought I'd share:

 

//rewrite the __doPostBack calls so that we can clear the ajax content 
//this prevents JSON primitive error on postback
$('a[href*="__doPostBack"]').each(function () {
  this.href = 'javascript:ClearAjax(); ' + this.href.replace('javascript:', '');
});
$('input[onclick*="__doPostBack"]').each(function () {
  this.onclick = 'ClearAjax(\'...\'); ' + this.onclick;
});

//clear or write simple content to div where content was written to by ajax call
function ClearAjax(content){

  $('div-ajax-content').html(content);

}

0
Vessy
Telerik team
answered on 13 Nov 2020, 07:11 AM

Hi,

Thanks a lot for sharing your solution with the community, Ben! I am sure it will be helpful for the other developers facing the same problem.

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeView
Asked by
Mike
Top achievements
Rank 1
Answers by
Simon
Telerik team
Mike
Top achievements
Rank 1
Ben Hobgood
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or