简体   繁体   English

获取asp标签值并放入javascript函数

[英]Get asp label value and put in javascript function

I have two label and I want to get the value and store in javascript function. 我有两个标签,我想获取值并存储在javascript函数中。 I want the value to put in pie chart label. 我希望该值放入饼图标签中。 Im only getting one and I don't know how to do it in another label. 我只能得到一个,而我不知道如何在另一个标签中做到这一点。 Please Help me. 请帮我。

Here is what I have so far. 这是我到目前为止所拥有的。

**Javascript ** ** JavaScript **

    var pie = 0;
    function changepie(val) {
        pie = val;
    }
    var pie2 = 0;
    function changepie2(val) {
          pie2 = val;
      }

Front end 前端

 <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"?</asp:Label>
 <asp:Label ID="Label2" runat="server" Text="Label" Visible="true"></asp:Label>

Another javascript for pie chart loading 饼图加载的另一个JavaScript

 window.onload = function () {
            var chart = new CanvasJS.Chart("chartContainer",
            {
                animationEnabled: true,
                animationDuration: 1300,
                backgroundColor: "transparent",
                legend: {
                    verticalAlign: "bottom",
                    horizontalAlign: "center"
                },
                data: [
                {

                    indexLabelFontSize: 10,
                    indexLabelFontWeight: "bold",
                    indexLabelFontFamily: "Helvetica",
                    indexLabelPlacement: "outside",
                    indexLabelLine: "none",
                    radius: "100%",
                    type: "pie",

                    toolTipContent: "{y} - <strong>#percent%</strong>",
                    dataPoints: [
                        { y: pie, legendText: "", 
                                    label: pie + "%", 
                                    indexLabelLineColor: "#1dc7ea", 
                                    indexLabelFontColor: "#1dc7ea", 
                                    exploded: true, 
                                    indexLabelPadding: "5px"
                                    },
                        { y: pie2, legendText: "",
                                    label: pie2, 
                                    indexLabelLineColor: "#FF4A55", 
                                    indexLabelFontColor: "#FF4A55" 
                                    }

                    ]
                }
                ]
            });
            chart.render();
        }

and here is my backend 这是我的后端

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    Label1.Text = Session("percent").ToString.Replace("<span class>", "").Replace("</span>", "")
    Label2.Text = Session("aaa").ToString
    ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + Label1.Text + ");", True)
    ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie2(" + Label2.Text + ");", True)
End Sub

in changepie function use this changepie功能中使用此

    var label1= 0;
        function changepie(lbael1,label2) {

             var chart = new CanvasJS.Chart("chartContainer",
            {
                animationEnabled: true,
                animationDuration: 1300,
                backgroundColor: "transparent",
                legend: {
                    verticalAlign: "bottom",
                    horizontalAlign: "center"
                },
                data: [
                {

                    indexLabelFontSize: 10,
                    indexLabelFontWeight: "bold",
                    indexLabelFontFamily: "Helvetica",
                    indexLabelPlacement: "outside",
                    indexLabelLine: "none",
                    radius: "100%",
                    type: "pie",

                    toolTipContent: "{y} - <strong>#percent%</strong>",
                    dataPoints: [
                        { y: lbael1+", ", legendText: "", 
                                    label: pie + "%", 
                                    indexLabelLineColor: "#1dc7ea", 
                                    indexLabelFontColor: "#1dc7ea", 
                                    exploded: true, 
                                    indexLabelPadding: "5px"
                                    },
                        { y: label2, legendText: "",
                                    label: pie2, 
                                    indexLabelLineColor: "#FF4A55", 
                                    indexLabelFontColor: "#FF4A55" 
                                    }

                    ]
                }
                ]
        }


----------
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    Label1.Text = Session("percent").ToString.Replace("<span class>", "").Replace("</span>", "")
    Label2.Text = Session("aaa").ToString
    ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + Label1.Text + "," + Label2.Text + ");", True)

End Sub

You ned to make sure if 你要确保

RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + Label1.Text + ");", True)

is getting called then you simply need to parseto int 被调用,那么您只需要parseto int

using 运用

Convert.ToInt32(Label1.Text)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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