Rodolfo Colón Ответов: 0

Aspx C # обновляет текстовое поле после ответа.addheader


Привет, ребята, веб-приложение используется для создания txt-файла, после создания файла мне нужно очистить некоторые значения текстового поля, поэтому код выглядит так.
private void WriteExportFile()
{
  Response.Clear();
  Response.ClearHeaders();
  Response.AddHeader("Content-Disposition", "attachment; filename=" + _exportFileName);
  Response.AddHeader("Content-Length", _exportFileOutputData.Length.ToString());
  Response.Write(_exportFileOutputData);
  Response.Flush();
  Response.End();
  //Instead of ResponseEnd use the below to fix a .Net bug that sometimes occurs with Response.End command
  HttpContext.Current.ApplicationInstance.CompleteRequest();
}

xml - это
<div class="FormButtons">
  <asp:Button ID="btExportBGData" CssClass="button" Text="Export Data" runat="server" OnClick="btExportBGData_Click" OnClientClick="ValidatePage('vgBritishGasExport','', true);">                        
</div>


Что я уже пробовал:

Я попытался добавить::

Ответ.AddHeader("обновить", "3; url=index.html");

но тема та же самая, как только файл создан, перезагрузка никогда не происходит.
Я читал, что, возможно, использование javascript возможно. но любую идею я оценю по достоинству.

Овации
Родольфо

F-ES Sitecore

It's hard to give a specific answer from the snippets you've given, but the general idea is that you need to make sure the call to writeexportfile happens in a request that is made to a new window\tab. As you are already calling js on the button click (ValidatePage), what you can do inside that ValidatePage function is if the validation is ok, update the "target" attribute of the form element to "_blank", and then make the changes you need to the elements on the page via js too. That will make the request to the code that writes the file happen in the "background" (for want of a better word) so the user still gets the "Save as" option, but it will also keep your existing page in the browser allowing you to change the form elements if you want.

0 Ответов