Response.WriteFile stopping previous request

I have a button that calls a click event to download a picture. In my click event I have some code to change my display as the Save dialog pops up. The issue I am having is that when the dialog comes up it stops the previous line of code from executing. How can I check to see that my code has executed before calling the function?

Here is my button event handler and function:

 protected void btnSave_Click(object sender, EventArgs e)
{
    var _title          = txtTitle.Text;
    txtTitle.Text       = string.Empty;
    txtDescription.Text = string.Empty;

    ChangeDisplay();

    if (Request.Browser.Browser == "IE")
        lblSnapShot.Visible = (lblSnapShot.Visible) ? false : true;

    SaveSnapShot(_title);
}

void SaveSnapShot(string _title)
{
    try
    {
        FileInfo _fileToDownload = new FileInfo(_path);
        Response.Clear();
        Response.ContentType = "image/png";
        Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + _title + ".png\"");
        Response.WriteFile(_fileToDownload.FullName);

        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    catch (System.Exception ex)
    {
        ChangeDisplay();

        if (Request.Browser.Browser == "IE")
            lblSnapShot.Visible = (lblSnapShot.Visible) ? false : true;

        Response.Write("SAVE FAILED \n Error: " + ex.Message);
    }
}

Answers


Response.WriteFile doesn't stop the processing of the other code (that code comes before you even call WriteFile so how could it?)

However, your SaveSnapshot method is sending back to the browser an image instead of the usual response of HTML. For each request from the browser, you can only send one response - you can't send back an image file and update HTML at the same time.


Need Your Help

Nokogiri HTML parse undefined method 'namespace_definitions' blows up on <o:p> tag

namespaces html-parsing nokogiri

I have a rails app that is parsing HTML using the nokogiri gem version 1.4.0

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.