views:

32

answers:

1

I have a few linkbuttons that each open the save dialog to let users save file to the local machine. But after any link is clicked the page is dead afterwards (nothing works) and page has to be refreshed.

So do I have to force refresh after download is complete or does it have to do something with postback?

{

        StringCollection strValuesToSearch = new StringCollection();

        strValuesToSearch.Add("findword");

        string stringToReplace;

        stringToReplace = TextBox1.Text;




        using (StreamReader reader = new StreamReader(Server.MapPath("~/test.txt")))
        {
            string result = reader.ReadToEnd();





            foreach (string s in strValuesToSearch)
            {

                if (result.Contains(s))

                    result = result.Replace(s, stringToReplace);




                Response.Clear();
                Response.AppendHeader("content-disposition", "attachment; filename=super.txt");
                Response.ContentType = "text/plain";
                UTF8Encoding encoding = new UTF8Encoding();
                Response.BinaryWrite(encoding.GetBytes(result));
                Response.Flush();
                Response.End();
+1  A: 

In the absence of client-side code, this is just a wild guess at what is causing the issue:

  1. User clicks on a link button
  2. JS initiates get or post ajax call to the server, sending some data
  3. Server sends content-disposition header followed by the file data
  4. ajax process expects some other header to say the action has completed and this header never arrives, so it waits endlessly locking the UI.
Majid