Loss of back navigation in ASP.NET

I have an ASP.NET2.0 web page with a submit button. When the user clicks, I generate an XML file on the fly and return it as a result.

Here is the code:

protected void submitBtn_Click(object sender, EventArgs e)
    {
        string result = this.ProduceMyXmlResult();

        this.Response.Clear();
        this.Response.StatusCode = 200;
        this.Response.ContentType = "application/xml";
        this.Response.ContentEncoding = System.Text.Encoding.UTF8;
        this.Response.Write(result);
        this.Response.End();
    }

      

The piece of code does exactly what I want. However, the browser doesn't recognize the XML file as a new page, so the BACK button won't take me back to the original page. Why and how can I overcome this?

+2


source to share


1 answer


The simplest way to do this, I think, would be to create a separate page that executes this code on page_Load () and redirects it when the button is clicked.

The reason you don't have back navigation is because the browser doesn't know the page has changed. Because the Submit button does a pre-postback and you are returning XML data in response to that postback, it appears in the browser as if it were just some transformation of the current page (as if you had, say, changed the text of the Label control).



The "correct" way to accomplish this would be with some type of HTTP handler, but I have no experience to suggest the correct way to do this, and you already have working C # code for this method.

+4


source







All Articles