Philly
Philly

Reputation: 251

File Download popup overwrites the alert popup

When the user clicks on the "Export to Excel" link, the standard "File download" dialog is presented to the user. See here for an example image.

But before exporting the excel file, I want to display an alert popup. But the Save dialog is obscuring the view of the alert popup.

How can I display the popup without it being obscured?

Here is my code...

dsResult = clsObj.getSearchResults_BL(detObj);

if (OrdDifference != null && OrdDifference.Any())
{
   ScriptManager.RegisterClientScriptBlock(this.up, this.GetType(), "export", "alert('.....')", true);
   set(dsResult, strName);
}
else
{
  set(dsResult, strName);
}

private void set(DataSet ds, string strFileName)
{
    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2007;
    IWorkbook workbook = application.Workbooks.Create(1);
    IWorksheet sheet = workbook.Worksheets[0];
    try
    {
        sheet.Name = strFileName;
        sheet.ImportDataTable(ds.Tables[0], true, 1, 1, -1, -1);

        ...

        workbook.SaveAs(strFileName, ExcelSaveType.SaveAsXLS, HttpContext.Current.Response, ExcelDownloadType.PromptDialog);

    }
    catch (Exception ex)
    {

    }
}

Upvotes: 0

Views: 1773

Answers (1)

Icarus
Icarus

Reputation: 63964

Your problem is here:

ScriptManager.RegisterClientScriptBlock(this.up, this.GetType(), "export", "alert('.....')", true);
set(dsResult, strName);

Because the set method in your program is writing to the Response Stream the call to ScriptManager.RegisterClientScriptBlock ends up doing nothing.

You need to do this on two steps:

if (OrdDifference != null && OrdDifference.Any())
{
   //Just do this, nothing more.
   ScriptManager.RegisterClientScriptBlock(this.up, this.GetType(), "export", "alertUser('Some Message Here')", true);

}

Now define the alertUser function in Javascript:

function alertUser(message)
{
    alert(message);
    window.location='AccepServiceOrder.aspx?o=Export';
}

Now on Page_Load check for the o parameter in the query string

protected void Page_Load(object sender, EventArgs e)
{
     if(Request.QueryString["o"]!=null)
     { 
        dsResult = clsObj.getSearchResults_BL(detObj);
         set(dsResult, strName);
     }
}

Upvotes: 1

Related Questions