在这里,我试图在单击一次按钮时执行两个函数,即一个 javascript 和一个 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" />
如果我尝试将System.Threading.Thread.Sleep用于 c# 代码,则 javascript 代码首先执行但不完全执行。它等到 c# 代码执行,最后同时生成两个输出。我希望它发生在另一个之后。有什么建议么?