Articles in this section
Category / Section

Exporting with Full Post and WaitingPopup in Asp Webforms

1 min read

Usually, in Grid export, waitingpopup cannot be rendered. Due to the full post, we cannot handle the Waitingpopup. However, this KB overcome those behavior using Browser Cookies.

 

Initialize the Grid:

 

    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <ej:Grid id="FlatGrid" runat="server" AllowPaging="True"
                OnServerWordExporting="FlatGrid_ServerWordExporting" 
                OnServerPdfExporting="FlatGrid_ServerPdfExporting" 
                OnServerExcelExporting="FlatGrid_ServerExcelExporting" > 
                <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,wordExport,pdfExport"></ToolbarSettings>
                <Columns>
                    <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="True" TextAlign="Right" Width="75" />
                    <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="80" />
                    <ej:Column Field="EmployeeID" HeaderText="Employee ID" TextAlign="Right" Width="75" />
                    <ej:Column Field="Freight" HeaderText="Freight" TextAlign="Right" Width="75" Format="{0:C}" />
                    <ej:Column Field="OrderDate" HeaderText="Order Date" TextAlign="Right" Width="80" Format="{0:MM/dd/yyyy}" />
                    <ej:Column Field="ShipCity" HeaderText="Ship City" Width="110" />
                 </Columns>
                <ClientSideEvents ToolbarClick="toolbarClick" />
            </ej:Grid>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="FlatGrid" />
        </Triggers>
    </asp:UpdatePanel>

 

In the ToolbarClick event, show the popup and set an interval to watch for the cookies from the server response. Once the cookies were found, clear the interval and hide the popup.

 

    <script>
        function toolbarClick(args) {
            var url = null;
            if (args.itemName.indexOf("Export") != -1) {
                this.element.ejWaitingPopup("show")
                var testVar = setInterval(ej.proxy(function () {
                    if (document.cookie.search("Export") != -1) {
                        //delete cookie
                        document.cookie = "Export" + "=;expires=Thu, 25 Aug 1994 00:00:01 GMT";
                        //hide the popup
                        this.element.ejWaitingPopup("hide");
                        clearInterval(testVar);
                    }
                }, this), 100);
            }
        }
    </script>

 

 

 

Before returning the response/exported file to the client-end, set the Cookies.

 

namespace sqlbinding
{
    public partial class _Default : Page
    {
        List<Orders> order = new List<Orders>();
        protected void Page_Load(object sender, EventArgs e)
        {
            BindDataSource();
        }
        private void BindDataSource()
        {
            int code = 10000;
            for (int i = 1; i < 10; i++)
            {
                order.Add(new Orders(code + 1, "ALFKI", i + 0, 2.3 * i, new DateTime(1991, 05, 15), "Berlin"));
                order.Add(new Orders(code + 2, "ANATR", i + 2, 3.3 * i, new DateTime(1990, 04, 04), "Madrid"));
                order.Add(new Orders(code + 3, "ANTON", i + 1, 4.3 * i, new DateTime(1957, 11, 30), "Cholchester"));
                order.Add(new Orders(code + 4, "BLONP", i + 3, 5.3 * i, new DateTime(1930, 10, 22), "Marseille"));
                order.Add(new Orders(code + 5, "BOLID", i + 4, 6.3 * i, new DateTime(1953, 02, 18), "Tsawassen"));
                code += 5;
            }
            this.FlatGrid.DataSource = order;
            this.FlatGrid.DataBind();
        }
 
        protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            ExcelExport exp = new ExcelExport();
            //Setting the cookie
            Response.Cookies["Export"]["isdone"] = "done";
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime");
        }
        protected void FlatGrid_ServerWordExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            WordExport exp = new WordExport();
            //Setting the cookie
            Response.Cookies["Export"]["isdone"] = "done";
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, "Export.docx", true, true, "flat-lime");
        }
        protected void FlatGrid_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            PdfExport exp = new PdfExport();
            //Setting the cookie
            Response.Cookies["Export"]["isdone"] = "done";
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, "Export.pdf", true, true,  true, "flat-lime");
        }
    }
 
}

 

Figure: Grid Exporting with Popup

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied