WebForm Server.Transfer - Variables are not being recorded in downloaded files

29 Views Asked by At

I'm using Server.Transfer and in the 2nd place I have a number of labels that are updated with a Request.Form["textbox_text"];

This all works really well, but the problem is I also want to write the content in that textbox to file like a word document using this method

Response.Clear();

Response.AddHeader("Content-disposition", "attachment; filename=Word.doc");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application / vnd.ms -word";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);

htw.Write("<table><h2><b>[ Text ]</b></h2><br>" + TextBox_name.Text + "</table>");

Response.Write(sw.ToString());
Response.End();

But whenever I check the file it will not have anything written on it. I've even tried to save the value of a Request.Form to a static variable and then write that variable but without any success.

1

There are 1 best solutions below

0
mxmissile On

How are you using Server.Transfer()? Post that code, make sure you are using the overload that preserves the form values:

Server.Transfer("page.aspx", true);