简体   繁体   English

Response.Redirect和MSCharts

[英]Response.Redirect and MSCharts

I've been working on a small application recently which consists of an index page containing a few reports run off a database, and then some forms to update the content of that page, all within ASP.NET using C#, in order to learn how to use MSCharts in future. 我最近一直在研究一个小型应用程序,该应用程序由一个索引页面组成,该索引页面包含一些在数据库中运行的报告,然后使用ASP.NET在某些表格中使用C#来更新该页面的内容,以了解如何在将来使用MSCharts。

The index page can display any of 5 reports I have set up, chosen via a drop down box. 索引页面可以显示通过下拉框选择的我已设置的5个报告中的任何一个。 By default, the first is selected such that there should always be a chart showing on the page. 默认情况下,选择第一个,以便页面上始终显示图表。

I got the charts functioning and showing what I wanted them to on the index page fine , and the forms to update the database did their job too. 我使图表起作用并在索引页面上很好地显示了我想要它们的内容,并且更新数据库的表单也完成了它们的工作。 However, when I clicked the "exit" button on one of these pages (which sent the user back to the index page), the chart that should have been displayed there was simply a red "x", as if the image did not exist. 但是,当我单击其中一个页面上的“退出”按钮(将用户返回索引页面)时,应该显示的图表只是一个红色的“ x”,就好像图像不存在一样。 。 If I refreshed the page it appeared as it should do. 如果刷新页面,它应该会显示。

The Exit buttons at the time used Response.Redirect() to send the user back to the index page, and I spent some time confirming this was the correct method. 当时的退出按钮使用Response.Redirect()将用户发送回索引页面,我花了一些时间来确认这是正确的方法。 In the end, I tried switching to use of Server.Transfer() instead, despite every site seeming to indicate that there was no major difference between the two in terms of the page execution cycle - only that Response.Redirect() sent a whole new request whereas Server.Transfer didn't. 最后,尽管每个站点似乎都表明在页面执行周期方面两者之间没有重大差异,但我还是尝试改用Server.Transfer()-仅Response.Redirect()发送了一个整体新请求,而Server.Transfer没有。

Despite all that, though, using Server.Transfer() fixed the issue. 尽管如此,使用Server.Transfer()解决了该问题。 Well, that's great! 好吧,太好了!

Can anyone explain why this worked? 谁能解释为什么这行得通吗?

Update - Some code, in case it helps at all. 更新 -一些代码,以防万一。

One of the events in question from the update forms - originally used Response.Redirect() of course. 更新表单中有问题的事件之一-当然是最初使用的Response.Redirect()。

    protected void Exit_Click(object sender, EventArgs e)
    {
        Server.Transfer("Default.aspx");
    }

The Page_Load from Default.aspx: 来自Default.aspx的Page_Load:

    protected void Page_Load(object sender, EventArgs e)
    {
        Report report = new Report(reportList.SelectedIndex);
        ChartPanel.Controls.Add(report.Chart);
    }

Outline of the Report class - this is basically a wrapper for the various reports I have specified in the createChartFromParameters() method. Report类的概述-这基本上是我在createChartFromParameters()方法中指定的各种报告的包装。 It simply does all the work of setting up the chart so it doesn't end up in the UI, and then lets the UI take the chart object itself. 它只是完成设置图表的所有工作,因此它不会最终出现在UI中,然后让UI接受图表对象本身。 I can post the implementation if someone would find it useful, but it's ugly as anything and really quite long-winded, so I'd rather not. 如果有人觉得它有用,我可以发布实现,但是它很丑陋,而且运行时间很长,所以我宁愿不这样做。

public class Report
{
    private Chart chart { public get; }

    public Report(string title, string command, string x, string y, string label, string legend, SeriesChartType type)

    public Report(int presetChartNum)

    private void createChartFromParameters(string title, string command, string x, string y, string label, string legend, SeriesChartType type, int customcode = 0)  
}

I believe this is a misunderstanding of how the server object and response object perform the redirection 我相信这是对服务器对象和响应对象如何执行重定向的误解

It has a lot to do with how the client is redirected to the new resource and from what end it does so, and what objects it has access to afterwards. 它与客户端如何重定向到新资源,从何处重定向到新资源以及事后可以访问哪些对象有关。

I could type it all out but there is a good resource here. 我可以全部输入,但是这里有很好的资源。

http://techahead.wordpress.com/2007/10/14/aspnet-servertransfer-vs-responseredirect/ http://techahead.wordpress.com/2007/10/14/aspnet-servertransfer-vs-responseredirect/

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

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