C# - SPLessons

Post Back does not work after writing files to response in ASP NET

Home > > Tutorial
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Post Back does not work after writing files to response in ASP NET

 Post Back does not work after writing files to response in ASP NET

Description :
After writing files to your system postback will not work sometime. For example if your exporting any data table as excel or csv files. After downloading that file postback will not work. To handle this type of situations you just add below code in your file.  

Step1 :
Add below function in your script.

[javascript] function setFormSubmitToFalse() { setTimeout(function () { _spFormOnSubmitCalled = false; }, 3000); return true; } [/javascript]

Step2 :
Call this function from your asp or html button

[c-sharp] <asp:Button runat="server" ID="BtnExporttoExcel" OnClick="BtnExporttoExcel_Click" OnClientClick="javascript:setFormSubmitToFalse()" /> [/c-sharp] In the above asp button click first it will call 'setFormSubmitToFalse()', it will set form submit to false then it will perform the action written on 'BtnExporttoExcel_Click'. After writing files also all post backs will work on page.   Post Back does not work after writing files to response in ASP NET