简体   繁体   中英

send parameter to Javascript from c#

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

在此处输入图片说明

coming javascript is:

在此处输入图片说明

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM