Javascript中的类访问函数

本文关键字:访问 函数 Javascript | 更新日期: 2023-09-27 18:16:34

我正试图在我的Asp.net网页上建立一个图表,我的代码如下文件后面的代码

            string WriteStr = "";
            WriteStr = "";
            WriteStr += "<?xml version='1.0' encoding='UTF-8'?>";
            if (DtIndsutry.Rows.Count > 0)
            {
                WriteStr += "<chart>";
                WriteStr += "<series>";
                for (int i = 0; i < DTTable.Rows.Count; i++)
                {
                    WriteStr += "<value xid='" + i + "'>";
                    string Data = DTTable.Rows[i]["Name"].ToString();
                    WriteStr += Data;
                    WriteStr += "</value>";
                }

                WriteStr += "</series>";
                WriteStr += "<graphs>";
                WriteStr += "<graph gid='1'>";
            }
            for (int i = 0; i < DTTable.Rows.Count; i++)
            {
                WriteStr += "<value xid='" + i + "'>";
                string percent= DTTable.Rows[i]["Percent"].ToString();
                WriteStr += percent;
                WriteStr += "</value>";
            }

            WriteStr += "</graph>";
            WriteStr += "</graphs>";
            WriteStr += "</chart>";
            Response.Write(WriteStr);

和我的aspx页面

            <script type="text/javascript" language="javascript">
     function GetBarChart() {
        var RequestUrl = "../Client/ChartPage.aspx";
        var oi = new SWFObject("../amcolumn/amcolumn.swf", "CategoryRet", "1000", "280", "8", "#ffffff");
        oi.addVariable("path", "../amcolumn/");
        oi.addVariable("settings_file", encodeURIComponent("../amcolumn/amcolumn_settings_mf.xml"));
        oi.addParam("wmode", "opaque");
        oi.addVariable("data_file", encodeURIComponent(RequestUrl));
        oi.write("GetBarChart");
    }

        <div id="GetBarChart">
            <script language="javascript" type="text/javascript">
                GetBarChart();
            </script>
        </div>

现在我的问题是,当我的代码后面包含一些其他的代码,当我试图创建这个图表发生的是数据打印在我的网页顶部的xml格式,我不想,

但是当我为图表创建一个单独的类时,图表显示良好。然而,第二种方法的问题是,我必须为每个图表创建一个新类,这也是不推荐的。

我怎样才能做到这一点?我可以使用javascript访问类中的方法吗?

谢谢大家

Javascript中的类访问函数

您是否尝试使用Page.ClientScript.RegisterStartupScript() ?

string jsScript = null;
jsScript = "<script type='text/javascript'>" + Constants.vbCrLf;
jsScript += "function GetBarChart();" + Constants.vbCrLf;
jsScript += "{" + Constants.vbCrLf;
                /* add your logic here */
jsScript += "}" + Constants.vbCrLf;
jsScript += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", jsScript);

您也可以参考此链接http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx