【问题标题】:Parser error when trying to generate gauge chart尝试生成仪表图时出现解析器错误
【发布时间】:2013-04-16 21:45:20
【问题描述】:

我正在尝试根据更改的 MTBF 值生成仪表图表,但是当我运行 web 应用程序时,我收到错误

解析器错误 说明:解析服务此请求所需的资源时出错。请查看以下特定的解析错误详细信息并适当修改您的源文件。

解析器错误消息:此处不允许使用“WebApplication1.WebForm3”,因为它没有扩展类“System.Web.UI.Page”。

来源错误:

第 1 行:
第 2 行: 第 3 行:
第 4 行:

源文件:/WebForm3.aspx 行:2

我使用的代码如下,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebApplication1 : System.Web.UI.Page
    {



        protected void Page_Load(object sender, EventArgs e)
        {



        }

        protected void Button1_Click(object sender, EventArgs e)
        {


            using (Testme entities = new Testme())
            {



                var execution = entities.TestExecutionDetails.Where(p => p.TestExecutionID == TestExecID).Select(p => p).OrderBy(p => p.StartTime).ToArray();
                var failures = entities.TestExecutionDetails.Select(p => p.Result != "Pass      ").Count();

                var uptime = entities.TestExecutionDetails.Where(p => p.Result == "Pass          ").Select(p => p);
                TimeSpan elapsedDuration = new TimeSpan(0);
                foreach (var p in uptime)
                {

                    elapsedDuration += (p.EndTime.Value - p.StartTime.Value);

                }
                var mtbfdisplay = elapsedDuration.TotalSeconds / failures;


                string str1 = @"

        data = google.visualization.arrayToDataTable([";

                string str2 = @"['Label', 'Value'],['MTBF'," + mtbfdisplay + @"],]);";

                string str3 = @"var options = {
                width: 400, height: 120, redFrom: 90, redTo: 100, yellowFrom: 75, yellowTo: 90, minorTicks: 5
            };


                var chart = new google.visualization.gauge(document.getelementbyid('chart-success'));
                chart.draw(data, options);";

                string postData = str1 + str2 + str3;

                Console.WriteLine(postData);


                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", postData, true);

            }


        }
    }
}

aspx代码如下

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Label ID="Label2" runat="server" Text="1"></asp:Label>
                <br />
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                <asp:HiddenField ID="HiddenField1" runat="server" Value="1" />
                <br />

                <asp:Label ID="Label1" runat="server" Text="1"></asp:Label>
                <br />

                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

                <div id="chart-success"></div>

            </ContentTemplate>


        </asp:UpdatePanel>
    </div>


    </form>
</body>
</html>

我真的卡住了,我什至不知道这是否是生成图表的正确方法,请帮忙。

谢谢

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    WebForm3 没有在任何地方声明(至少在您发布的代码中),所以很可能是这一行:

    public partial class WebApplication1 : System.Web.UI.Page
    

    应该是

    public partial class WebForm3 : System.Web.UI.Page
    

    【讨论】:

    • 非常感谢,这真的是一件值得忽略的大事……再次感谢!
    • 现在,我不知道为什么没有生成图表 :( ,你能给我一些建议吗?
    • @Archer,以前从未使用过此 API,但很可能与更新面板有关。尝试在没有人的情况下做同样的事情。如果您对此仍有疑问 - 最好不要混合问题并单独发布一个问题,详细描述“图表未生成”的含义。
    • 谢谢安德烈,会发布一个不同的问题
    • 我不确定这是不是问这个问题的正确地方,但似乎没有人回答我的问题stackoverflow.com/questions/16039350/… 围绕这个问题,这个问题是模棱两可还是写得不好?请告诉我,以便我纠正。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 2019-06-25
    • 2012-05-02
    相关资源
    最近更新 更多