문제

I have a home/main menu page. There's a link to the form. If you run the form with inputs, you get Excel output. If you click 'open' to open that output in the browser, the back-button takes you to the home/main menu.

Which is understandable, since if the form page is X.aspx, the binaryWrite that outputs the Excel doesn't really change that.

The problem is that if there's a postback, the back button takes you to the form page. This is inconsistent. If I run the page or a drop down causes a postback, I really want the back-button to take me to the form field, so that I can run the excel sheet again.

Things I've tried.

I tried adding a location header.

e.ContentFileName = "ELTFile.Output.xls";

Before the response.Writing ...

private void SendFileToBrowser(DownloadFileEventArgs e)
{
    if (!e.Cancel && e.FileObject != null)
    {
        this.Page.Response.Clear();
        this.Page.Response.ClearContent();
        this.Page.Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", e.ContentFileName));
        this.Page.Response.AddHeader("Content-Length", e.FileObject.LongLength.ToString());
        this.Page.Response.AddHeader("Location", e.ContentFileName);
        this.Page.Response.ContentType = e.ContentType;
        this.Page.Response.BinaryWrite(e.FileObject);
        this.Page.Response.End();
    }
}

And I tried

Response.Cache.SetCacheability(HttpCacheability.Public);

As well as

Response.Cache.SetCacheability(HttpCacheability.Server);

But basically, depending on whether or not I post back before I click the 'Submit' button to generate the Excel, I get the main menu (don't want) or the form page (want). I want the form page every time. Basically I want to tell the browser "I know it's not really a different page, but treat it that way, will ya please?"

도움이 되었습니까?

해결책

You cannot directly add pages to a browser history.

You could make your application such that the form is always a page ahead of the excel output.

To do this, have a separate page to output the excel. When you have the inputs to generate the excel, Response.Redirect to the generation page. This will keep your input form in the browser history.

Note: you could redirect to the same page too if you liked, but that would need you to track it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top