0

ここでは、1 回のボタン クリックで 2 つの関数、つまり 1 つの JavaScript と 1 つの C# コードを実行しようとしています。問題は、両方の関数が同時に実行されていることです。私の関数は次のとおりです。

JavaScript 関数

 function exportCharts() {
            var exportFormat = 'JPG';
            initiateExport = true;
            for (var chartRef in FusionCharts.items) {
                if (FusionCharts.items[chartRef].exportChart) {
                    document.getElementById("linkToExportedFile").innerHTML = "Exporting...";
                    FusionCharts.items[chartRef].exportChart({ "exportFormat": exportFormat });
                }
                else {

                    document.getElementById("linkToExportedFile").innerHTML = "Please wait till the chart completes rendering...";
                }
            }
        }

c# コード:

 protected void imgBTNExportPPT_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                PredictExportToPPT objOExporttoPPT = new PredictExportToPPT();

                PredictionModel();

                string reportNames = ObjCommon.GetBIReportNames("Prediction", "Report");
                reportNames += ObjCommon.GetBIReportNames("Prediction", "Table");

                objOExporttoPPT.ExportToPPTPredict(ObjPredictInputParameter, reportNames, ObjSharedEntities.PredictTableData);

                string itemname = "PPTOutput.pptx";
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "pptx";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + itemname + "");
                HttpContext.Current.Response.BinaryWrite(System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(DataTemplate.PPTOutputTemplateFilePath)));
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.End();

            }
            catch (Exception exceptionMessage)
            {
                throw (exceptionMessage);
            }
            finally
            {
                GC.Collect();
            }
        }

ボタンクリックコード

 <asp:ImageButton ID="imgBTNExportPPT" runat="server" Width="15" Height="15" border="0" OnClientClick="return exportCharts()" OnClick="imgBTNExportPPT_Click" />

C# コードにSystem.Threading.Thread.Sleepを使用しようとすると、JavaScript コードが最初に実行されますが、完全には実行されません。C# コードの実行まで待機し、最終的に両方の出力が同時に生成されます。他の後。助言がありますか?

4

1 に答える 1

2

私はそれをテストしました

<asp:ImageButton ID="imgBTNExportPPT" runat="server" Width="15" Height="15" border="0" OnClientClick="exportReport()" OnClick="imgBTNExportPPT_Click" />

   <script>
            function exportReport() {
              exportCharts();
             __doPostBack("imgBTNExportPPT","");
         }
    </script>

マスター ページを使用している場合は、次のようになります。

交換

__doPostBack("imgBTNExportPPT","");

__doPostBack("ctl00$MainContent$imgBTNExportPPT", "");
于 2012-06-27T14:18:14.983 に答える