ASP.NET WebHelpers Library,Chart

时间:2017-05-05 09:44:35

标签: c# html asp.net

所以基本上我想使用webhelpers库中的图表我正在使用Visual Studio Webforms(aspx)。 我的想法是点击按钮然后出现图表(不要介意其他按钮和文本框,它们来自我以前做过的另一个测试。我是aspx的新手)。但是,当我点击按钮时,整个页面都会被“吃掉”#34;按图表。按钮消失,唯一保留的是图表。任何想法为什么会发生这种情况?

第1页html代码:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>Pagina 1</div>
        <asp:Label ID="Lbl_nome" runat="server" Text="Nome"></asp:Label>
        <asp:TextBox ID="TxtBx_nome" runat="server"></asp:TextBox>

        <asp:Label ID="Lbl_apelido" runat="server" Text="Apelido"></asp:Label>
        <asp:TextBox ID="TxtBx_apelido" runat="server"></asp:TextBox>

        <div>
            <asp:Button ID="Btn_enviar" runat="server" Text="Enviar" OnClick="Btn_enviar_Click" />
        </div>

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

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

第一页aspx.cs代码:

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 WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 

            }
            else {

            }



        }

        protected void Btn_enviar_Click(object sender, EventArgs e)
        {
            Response.Redirect("WebForm2.aspx?apelido=" + TxtBx_apelido.Text + "&nome=" + TxtBx_nome.Text + "");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //Response.Redirect("WebFormChart.aspx");          //Faz redirect para a pagina     diferença?
            //Server.Transfer("WebFormChart.aspx");           //Faz redirect para a pagina      diferença?
              Server.Execute("WebFormChart.aspx");           //Faz include do conteodo da pagina
            //Response.WriteFile("WebFormChart.aspx");      //Escreve a pagina
        }


    }
}

第2页html代码:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        This text wont show idk why
    </form>
</body>
</html>

第二页aspx.cs代码

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

namespace WebApplication1
{
    public partial class WebFormChart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var myChart = new Chart(width: 600, height: 400, theme: ChartTheme.Vanilla3D)
                   .AddTitle("Title")
                   .AddSeries(chartType: "pie",
                       xValue: new[] { "name1", "name2", "name3", "name4", "name5" },
                       yValues: new[] { "4", "6", "4", "5", "7" });
            myChart.Write();

        }
    }
}

结果是:

Page 1 with the button for showing the chart hightlighted

Page 2 with the chart as you can see the text i had put there is gone

抱歉可能是英文不好。

0 个答案:

没有答案