画面から出力されたテキストをテキストファイルとしてダウンロードしようとしています。以下はコードです。一部のページでは機能していますが、他のページではまったく機能していません。誰かがここで何が悪いのか提案できますか?
protected void Button18_Click(object sender, EventArgs e){
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "text/plain";
    Response.AppendHeader("content-disposition", "attachment;filename=output.txt");
    StringBuilder sb = new StringBuilder();
    string output = "Output";
    sb.Append(output);
    sb.Append("\r\n");
    Response.Write(sb.ToString());
}