2

I am trying to show user a progress bar during the uploadFile. I can get the percentage in back end through the method below, however I cannot manage to print the percentage returned by e.PercentageProgress to display to the user.

  static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
  {
        // Need to show this on a label or return to front end somehow
        System.Diagnostics.Debug.WriteLine(e.PercentageProgress);            

        e.Cancel = false;
  }

The question is how can I get the e.PercentageProgress to show on an aspx page or get it to use in javascript?

4

1 回答 1

0

尝试这样的事情:

public class ProgressInformer {

    public static string Progress = "0";

    static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
    {

        // print a dot           
        System.Diagnostics.Debug.WriteLine(e.PercentageProgress);

        // Need to show this on a label or return to front end somehow
        ProgressInformer.Progress = e.PercentageProgress.ToString();

        e.Cancel = false;
    }
}

现在,由于您正在使用值设置静态变量,因此您可以从其他地方访问它。然后,您可以使用该值使用某种方法或服务在前端回显。可能是这样的:

public string EchoToFrontEnd()
{
    return ProgressInformer.Progress;
}

限制:如果这对您仍然有效,则此解决方案不是线程安全的。这意味着,您无法回显多个下载的进度。您一次只能下载一次。

希望这可以帮助...!

于 2016-04-24T16:21:38.400 回答