locked
Even is not rising once after clicking Download report? RRS feed

  • Question

  • Below is my code:-

    public void ExportToExcel()
            {
                DataTable dataTab = BindListItemToDataTable();
                if (dataTab.Rows.Count > 0)
                {
                    string fileName = "ExportItems.xls";
                    System.IO.StringWriter strWriter = new System.IO.StringWriter();
                    System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
                    DataGrid grid = new DataGrid();
                    grid.DataSource = dataTab;
                    grid.DataBind();
                    grid.RenderControl(htmlWriter);
                    Response.ContentType = "application/vnd.ms-excel";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + "");
                    this.EnableViewState = false;
                    Response.Write(strWriter.ToString());
                    Response.End();
                }
            } 

    When I click first time on Download button  It works fine, but again I  click on same button or any other button on the form then event not  riseing (Paused). Please help me out in this.

    Thanks,

    Vishwa

    Friday, October 12, 2012 6:26 AM

Answers

  • Hi,

    SharePoint registers a JavaScript "on submit" handler and handler global variable _spFormOnSubmitCalled is set to true. SharePoint uses this variable to check if a submit was executed and prevents any further submits. Since your "download postback" does not refresh the page this variable remains true. With the effect that that all other buttons stop working.

    As a workaround you can set this variable to false in a client click handler on your download button:

    Button btn = new Button();
    btn.Text = "Download";
    btn.Click += DownloadButton_Click;
    
    // set the client click handler
    btn.OnClientClick = "window.setTimeout(function() { _spFormOnSubmitCalled = false; }, 10);"
    

    Check this thread for more info: http://stackoverflow.com/questions/7749393/no-more-post-back-after-file-download-in-sharepoint

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Friday, October 12, 2012 7:18 AM
    Moderator

All replies

  • Hi,

    Use below line in your pageload event:

    if(!Page.IsPostBack)
    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Friday, October 12, 2012 6:40 AM
    Moderator
  • Hi,

    SharePoint registers a JavaScript "on submit" handler and handler global variable _spFormOnSubmitCalled is set to true. SharePoint uses this variable to check if a submit was executed and prevents any further submits. Since your "download postback" does not refresh the page this variable remains true. With the effect that that all other buttons stop working.

    As a workaround you can set this variable to false in a client click handler on your download button:

    Button btn = new Button();
    btn.Text = "Download";
    btn.Click += DownloadButton_Click;
    
    // set the client click handler
    btn.OnClientClick = "window.setTimeout(function() { _spFormOnSubmitCalled = false; }, 10);"
    

    Check this thread for more info: http://stackoverflow.com/questions/7749393/no-more-post-back-after-file-download-in-sharepoint

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Friday, October 12, 2012 7:18 AM
    Moderator
  • Hi Hemendra,

    Thanks a lot. Really this solution helped me.

    Thanks,

    Vishwa

    Friday, October 12, 2012 8:34 AM
  • Hi Hemendra,

    It's a very helpful solution

    Thanks a lot !!!

    Rohit Warghade

    Friday, October 19, 2012 5:10 AM