0

ユーザーが [Excel にエクスポート] リンクをクリックすると、標準の [ファイルのダウンロード] ダイアログが表示されます。画像の例については、こちらを参照してください

しかし、Excel ファイルをエクスポートする前に、警告ポップアップを表示したいと考えています。ただし、[保存] ダイアログがアラート ポップアップのビューを覆い隠しています。

ポップアップを隠さずに表示するにはどうすればよいですか?

これが私のコードです...

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)
    {

    }
}
4

1 に答える 1

1

あなたの問題はここにあります:

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

プログラムのsetメソッドが応答ストリームに書き込んでいるため、への呼び出しはScriptManager.RegisterClientScriptBlock何もしません。

これは2つのステップで行う必要があります。

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

}

alertUser次に、Javascriptで関数を定義します。

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

次に、クエリ文字列Page_Loadのパラメータを確認しますo

protected void Page_Load(object sender, EventArgs e)
{
     if(Request.QueryString["o"]!=null)
     { 
        dsResult = clsObj.getSearchResults_BL(detObj);
         set(dsResult, strName);
     }
}
于 2012-09-13T15:12:47.120 に答える