[英]Calling server-side C# function from either javascript or codebehind c# function ASP.NET
[英]Calling a javascript function asynchronosly from server side in c#
這是我的代碼:
protected void BtnImport_Click(object sender, EventArgs e)
{
List<DataTable> tb = Helper.SplitTableToManyTables(FileTb, 50); // a list containing multiple DataTable each have 50 rows
int importedRowsCount = 0;
for (int KLoop = 0; KLoop < tb.Count; KLoop++)
{
...
if (QueriesDataHelper.ImportContacts(resTb, int.Parse(TxtHiddenGroupId.Value), Session))
{
importedRowsCount += resTb.Rows.Count;
var script = "DisplayProgressMsg(" + importedRowsCount + ")";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", script, true);
if (KLoop == tb.Count - 1)
MessageBox.Show(importedRowsCount.ToString()+" Contacts imported successfully");
}
}
}
QueriesDataHelper.ImportContacts是一個函數,該函數獲取包含50行的dataTable並將其發送到存儲過程
我的問題是在所有數據表都插入后我要執行RegisterStartupScript,我想在第一個數據表完成后顯示ms
好,
Http是請求/響應協議。 但是您要發送對單個請求的多個響應。
我為您看到兩種方式。 在這兩種方法中,您都必須在單獨的線程中運行長時間運行的進程。 然后
1)使用ajax,每隔N秒向服務器詢問進度,並顯示結果。 客戶的進度會有所延遲
2)Web套接字( SignalR非常適合此類用途)。 這樣,您將能夠實時顯示進度,但是我認為很難實施
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.