0

I have a page where users can add attachments to emails. When they click to start uploading their attachments, I run a bit of javascript to set a label to read (for example) 'Uploading File 1 of 4'

The code that handles the upload is below. As each file is saved, I want to update the browser label to read (for example) 'File 1 uploaded. Uploading File 2 of 4'. Etc.

What technique can I use to keep the browser notified as the files are updated? I don't need a progress bar.

HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
    {
    hpf.SaveAs(path + ReturnValue.ToString() + "\\" + Path.GetFileName(hpf.FileName));
    //This is where I want to update the browser so the user is informed as each file is uploaded
    }
}

I tried using Response.Write to write <script type="text/javascript">alert('File 1 uploaded')</script> just to see if that would do anything. But it does not work.

I tried using ScriptManager.RegisterStartUpScript to call a function but that didn't work.

4

1 回答 1

1

正常的方法是使用 AJAX 在服务器端轮询 Web 方法——这是一种返回当前数据的方法。

一个问题是服务器可能正在使用会话同步,因此您需要使用无会话 Web 方法。

于 2012-09-18T20:16:34.687 回答