Invalid JSON Primitive

5 posts, 1 answers
  1. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 08 Jun 2008 Link to this post

    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
  2. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 11 Jun 2008 Link to this post

    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
  3. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 16 Jun 2008 Link to this post

    Hi Simon,

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

    Mike
  4. Ben Hobgood
    Ben Hobgood avatar
    3 posts
    Member since:
    Sep 2004

    Posted 12 Nov 2020 Link to this post

    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);

    }

  5. Vessy
    Admin
    Vessy avatar
    2369 posts

    Posted 13 Nov 2020 Link to this post

    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/.

Back to Top