您應該知道的是,您無法使用標準FileUpload控件檢查文件上載的狀態。你可以做的是將文件上傳到服務器上,然後使用ODBC連接到它,並開始讀取並在數據庫中異步插入行(通過向頁面發出ajax請求或使用腳本服務)。
就進度條而言,您應該簡單地使用CSS progres欄(您可以在http://css-tricks.com/examples/ProgressBars/找到一個簡單示例)。
然後,你應該建立一個腳本服務(使用網絡serivice)用方法,可以從服務器返回的進展情況:
你的* .asmx文件應該包含這樣的:
[WebMethod]
public int GetStatus()
{
int progress = 0; // in percents
// your server-side code here
return progress;
}
你的aspx頁面應該包含這樣的:
<asp:ScriptManager runat="server" ID="ScriptManager">
<Services>
<asp:ServiceReference Path="~/services/import.asmx" InlineScript="false" />
</Services>
</asp:ScriptManager>
然後,你應該能夠定期調用該方法從JavaScript(每一秒的examp嘞,使用的setTimeout),並用簡單的JavaScript或jQuery的更新進度條寬度:
var tout, service;
function UpdateStatus() {
if (tout != null)
clearTimeout(tout);
if (service == null)
service = new namespace.here.serice_class_here();
service.GetStatus(onSuccess, onFailure);
}
function onSuccess(result) {
// update the width of the progress with result (the integer value of the progress)
progress_bar.style.width = percent + "%";
// call the method again
tout = setTimeout("UpdateStatus()", 1000);
}
function onFailure(error) {
alert(error.get_message());
}
你可以擴展您的onSuccess JavaScript函數和進度完成時(返回值爲100%),你可以將用戶重定向到另一個頁面或根據您的需要顯示信息或按鈕。
我希望這有助於!