0

I have some problems on javascript. I am sending parameter to js sending data is:

enter image description here

coming javascript is:

enter image description here

c# code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' JSonID.Value = "{""id"":""1"",""name"":""1"",""data"":""0,3048"",""children"":[{""id"":""11"",""name"":""11"",""data"":""0,3048"",""children"":[{""id"":""111"",""name"":""111"",""data"":""0,3048"",""children"":[]},{""id"":""112"",""name"":""112"",""data"":""0,3048"",""children"":[{""id"":""1121"",""name"":""1121"",""data"":""0,3048"",""children"":[]},{""id"":""1122"",""name"":""1122"",""data"":""0,3048"",""children"":[]}]}]},{""id"":""12"",""name"":""12"",""data"":""0,3048"",""children"":[]},{""id"":""13"",""name"":""13"",""data"":""0,3048"",""children"":[{""id"":""131"",""name"":""131"",""data"":""0,3048"",""children"":[{""id"":""1311"",""name"":""1311"",""data"":""0,3048"",""children"":[]}]},{""id"":""132"",""name"":""132"",""data"":""0,3048"",""children"":[]}]},{""id"":""14"",""name"":""14"",""data"":""0,3048"",""children"":[]}]}"
    'ScriptManager.RegisterStartupScript(UpdatePanel1, Me.GetType(), "GraphFunction", "drawChart()", True)

    If Page.IsPostBack AndAlso GraphNames.SelectedIndex >= 0 Then
        SetGraph(GraphNames.SelectedIndex)
    End If

    If Not Page.IsPostBack Then
        OnOffCheck.Items.Add("On")
        OnOffCheck.Items.Add("Off")
        Menu1.Items(0).Selected = True

        StaticService.CreateErrorDictionary()
        RunDBInfo()

        Label4.Text = ""
        If Page.IsPostBack AndAlso GraphNames.SelectedIndex >= 0 Then
            SetGraph(GraphNames.SelectedIndex)
        End If
    End If

    Dim graphString = jSerializer.Serialize(ObjList)
    ScriptManager.RegisterStartupScript(UpdatePanel1, Me.GetType(), "GraphFunction", "drawChart('" & graphString & "')", True)

End Sub

Javascript code:

 function drawChart(graphInput) {
        //                                        var data = google.visualization.arrayToDataTable([
        //                      ['X', 'Points', 'Line'],
        //                      [3, 3.5, 1],
        //                      [4, 5.5, 2],
        //                      [4, 5, null],
        //                      [6.5, 7, 3],
        //                      [8, 12, 4],
        //                      [11, 14, 5]
        //                    ]);
        //  alert(1);
        // var data = JSON.parse('<%=jSerializer.Serialize(ObjList)%>');
        alert(graphInput);
        var data = JSON.parse(graphInput);
        alert(data);
        dLen = data.length;

        var tabledata = new google.visualization.DataTable();
  ...

What is the problem ? how can i recieve data properly in javascript ?

1
  • That's not C#. That appears to be Visual Basic .NET Jan 29, 2015 at 18:31

1 Answer 1

0

graphString is not being initialized as a string. You didn't specify a type so therefore Object is assumed. Does jSerializer.Serialize(ObjList) actually return a string? If so, try initializing graphString as a proper string:

Dim graphString As String = jSerializer.Serialize(ObjList).

2
  • you are perfecto !! . i could not understand how i did not see object problem :( By the way, i could not understand why visual basic does not give any error :s Jan 30, 2015 at 18:22
  • There was no error because what you had before was syntactically correct (at least without having Option strict turned on). It was just that you wanted to send a string variable to javascript but you were sending an object variable instead. In fact I'm thinking that you would have been able to get it to work the original way as well by converting the object to string in javascript, but I think passing the string from the beginning is a better solution.
    – Joe Uhren
    Jan 30, 2015 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.