你可以用UpdatePanel做到這一點。這將需要一點小小的詭計,但嘗試這樣:
1)將UserControl
放入UpdatePanel
。
2)在您的用戶控件上放置一個公共屬性,如IsEnabled
,它將用於有條件地不做任何事情或呈現「請稍候」。從主頁面設置爲false。
3)OnInit
添加一些代碼,您的主頁:
if (MyScriptManager.IsInAsyncPostback) {
MyUserControl.IsEnabled=true;
}
4)添加客戶端腳本沿着這些線路:
finished=false;
Sys.WebForms.PageRequestManager.pageLoaded(function(sender,args) {
if (!finished) {
finished=true;
__doPostBack('','');
// you can include the uniqueID of your updatepanel as the first arg
// otherwise it will refresh all update panels
}
});
或使用jQuery ..
finished=false;
$(document).ready(function() {
if (!finished) {...
}
});
這是什麼應該做的是使頁面加載完成後,這將反過來導致更新面板被刷新立即啓動一個異步回發。由於您在異步回發中將其設置爲啓用,它將在第二次呈現自己。
您可能會考慮發佈需要7秒左右才能執行的代碼。這是運行一些計算和查詢所需的大量時間。聽起來好像數據庫需要更好的索引 – NotMe 2011-03-25 19:28:59