如何在C#.net中单击ASP按钮时停止JS执行?

时间:2017-09-20 06:12:21

标签: javascript c# canvasjs

我遇到这个问题,当我点击C#.net上的一个按钮时,它会重新加载JS并显示空白。

请帮助,因为当我点击按钮加载代码后,javascript被加载并且div id =" chartContainer"用空结果刷新。

它继续重新加载,不会显示准确的结果。只是空的。它首先加载OK,但是一旦我点击按钮,它将刷新容器使其变空。

        

        <div class="row">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <asp:Label ID="Label2" runat="server" Text="Monthly RQ (Plan vs Actual)"></asp:Label>
                </div>
                <div id="chartContainer" style="height: 350px; width: 100%;">
                </div>
                <div>
                    <asp:LinkButton ID="lnkSearch" runat="server" CssClass="btn btn-white btn-info btn-round">
                    <i class="ace-icon fa fa-search bigger-120 blue"></i>
                        Search
                    </asp:LinkButton>
                </div>                  
            </div>
        </div>      

我的Javascript:

 <% if (!IsPostBack)
   { %>
<script type="text/javascript">
    window.onload = function () {
        var chart = new CanvasJS.Chart("chartContainer", {
            theme: "theme3",

            //interactivityEnabled: true,
            animationEnabled: true,
            animationDuration: 2000,   //change to 1000, 500 etc
            zoomEnabled: true,

            title: {
                text: "HPM Rolled Quantity (<%= String.Format("{0:MMMM}", DateTime.Now) %> <%= DateTime.Now.Year.ToString() %>)"
            },
            toolTip: {
                enabled: true,       //disable here
                animationEnabled: true //disable here
            },


            exportFileName: "HPM RQ Report",  //Give any name accordingly
            exportEnabled: true,

            axisX: {
                valueFormatString: "####",
                interval: 1
            },
            axisY: [{
                title: "RQ (Ton)",
                lineColor: "#369EAD",
                titleFontColor: "#369EAD",
                labelFontColor: "#369EAD",

            },
            ],
            axisY2: [{
                title: "RQ (Pcs)",
                lineColor: "#7F6084",
                titleFontColor: "#7F6084",
                labelFontColor: "#7F6084"
            },
            ],

            data: [
            {
                //indexLabel: "{y}",
                //indexLabelPlacement: "inside",
                //indexLabelOrientation: "vertical",
                //indexLabelFontColor: "black",
                //bevelEnabled: true,
                type: "column",
                showInLegend: true,
                //axisYIndex: 0, //Defaults to Zero
                name: "RQ Plan (MT)",
                xValueFormatString: "####",
                dataPoints: [
                    <%=HPMDataRQ_P%>
                ]
            },
              {
                  type: "column",
                  showInLegend: true,
                  axisYIndex: 1, //Defaults to Zero
                  name: "RQ Actual (MT)",
                  xValueFormatString: "####",
                  dataPoints: [
                    <%=HPMDataRQ_A%>
                  ]
              },
              {
                  type: "spline",
                  lineDashType: "dash",
                  showInLegend: true,
                  axisYType: "secondary",
                  axisYIndex: 1, //Defaults to Zero
                  name: "RQ Plan (Pcs)",
                  xValueFormatString: "####",
                  dataPoints: [
                      <%=HPMDataPCs_P%>
                  ]
              },
              {
                  type: "spline",
                  showInLegend: true,
                  axisYType: "secondary",
                  axisYIndex: 1, //When axisYType is secondary, axisYIndex indexes to secondary Y axis & not to primary Y axis
                  name: "RQ Actual (Pcs)",
                  xValueFormatString: "####",
                  dataPoints: [
                      <%=HPMDataPCs_A%>
                  ]
              }
            ]
        });

        chart.render();
    }
</script>

<% } %>

0 个答案:

没有答案