2009-02-06 70 views
7

我試圖顯示更新進度加載圖像,每當我的更新面板它是Ajax的東西。我環顧教程,看起來非常簡單,但我沒有運氣。這是一個很值得我有什麼...無法讓ASP.Net UpdateProgress顯示

<div id="panelWrapper"> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:UpdateProgress ID="TaskUpdateProgress" runat="server" DynamicLayout="False" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0"> 
      <ProgressTemplate> 
       <asp:Image ImageUrl="~/Images/ajax-loader.gif" Width="16px" Height="16px" runat="server" ID="TaskLoadingImage"/> 
      </ProgressTemplate> 
     </asp:UpdateProgress> 

     <div id="UrlDiv" class="URLNotification"> 
      <asp:Label ID="UrlLabel" runat="server" Text="URL:" AssociatedControlID="Url" /> 
      <asp:HyperLink ID="Url" runat="server" Text="Click &quotGenerate" to create the URL." /> 
     </div> 

     <br /> 

     <asp:CheckBoxList runat="server" ID="IncludeItems" TextAlign="Right"> 
      <asp:ListItem Selected="True">Include 1</asp:ListItem> 
      <asp:ListItem Selected="True">Include 2</asp:ListItem> 
     </asp:CheckBoxList> 

     <br /> 

     <div id="buttons" style="display:inline;"> 
      <asp:Button ID="Generate" runat="server" OnClicked="Generate_Clicked" Text="Generate" /> 
      <asp:Button ID="Add" runat="server" OnClientClick="add();" Text="Add"/> 
     </div> 
    </ContentTemplate> 
</asp:UpdatePanel> 

我也有一個樣式一些絕對定位的造型。我已經嘗試了一些你在這裏看到的變體,並且沒有找到關於可能是什麼問題的很多好的信息。有任何想法嗎?如果你需要別的東西,讓我知道。

編輯:我發現唯一的新信息是...

「在下列情況下,UpdateProgress控件將不會自動顯示:

UpdateProgress控件與特定的關聯更新面板,但異步回髮結果來自不在該更新面板內的控件。

UpdateProgress控件未與任何UpdatePanel控件關聯,並且異步回發不是由不在UpdatePanel內的控件產生的並不是一個觸發。例如,更新是在代碼中執行的。「

我非常有信心,這些都不適合我的情況。所發生的是按鈕(它位於更新面板內)被點擊調用一些後面的代碼集的重新加載了更新面板中的URL文本。

+1

請注意,UpdateProgress控件具有DisplayAfter參數,該參數指定在顯示內容之前必須通過的時間(以毫秒爲單位)。默認情況下,它是500毫秒,所以如果你的Ajax操作比這個快(而且很多),那麼你將看不到進度指示器。爲了測試這個,你可以使用Threading.Thread.Sleep(1000)將延遲引入服務器端處理,延遲時間爲1秒。然後你應該看到更新進度的內容。請參閱https://blogs.msdn.microsoft.com/kashif/2006/11/08/updateprogress-control-in-asp-net-ajax/ – 2016-04-19 14:49:35

回答

2

我想我想通了什麼事情裏面。這個問題是不與任何我在UpdateProgress或Panel上做錯了,我在後臺加載了其他的東西,顯然阻止了UpdatePanel的Ajaxyness。

所以基本上發生的是加載圖標不會顯示在初始頁面加載。我意識到這一點,因爲我實際上一直等到頁面上的所有內容完全加載後纔會觸發按鈕。果然,裝載機出現了。

我認爲更新面板刷新至少會在點擊事件被聽到的時候被請求,所以加載器圖標會在其他東西加載的時候立即顯示。這似乎並不是這種情況,雖然...

4

不要把更新進度控制更新面板控制

+1

感謝您的快速響應,但我已經走下了這條路,我只是想再次檢查。仍然不是運氣。此外,UpdateProgress的asp.net示例頁面說:「您可以將UpdateProgress控件放入UpdatePanel控件內部或外部。」 – Carter 2009-02-06 18:41:57

+0

嗯,你有沒有試過拿出圖像控制,只是把一些靜態文本,以確保您的圖像路徑是正確的? – Element 2009-02-06 19:06:26

4

我也有UpdateProgressPanel相同的問題。 我發現,當你放置一個UpdateProgressPanel並將它關聯到一個UpdatePanel時,從該UpdatePanel的任何回發將導致UpdateProgressPanel顯示。

另一個訣竅是如果頁面上有一個UpdatePanel,則刪除AssociatedUpdatePanel參數,這將導致UpdateProgressPanel顯示發生的每個異步回發。

UpdateProgressPanel可以放在代碼中的任何地方,除了那些有預定義標籤的區域。它可以放在UpdatePanel的內部或外部,它會顯示你是否正確放置了它的CSS,將它關聯到一個UpdatePanel,或者只是把它放在那裏,如果發生異步回髮結果,它就會顯示出來。

2

我的項目從VS2008轉換到VS2010後,真的很難過。UpdateProgress突然停止工作,這在VS2008中很好。花了整整一個下午搜尋答案並試驗這個,最後我發現Scott Gu's posting出了什麼問題。

這是一個自動生成的web.config條目'xhtmlConformance mode =「Legacy」'。

禁用此功能後,它再次開始工作。可能不是你的情況,但只是爲同樣的問題掙扎的人。

快樂編碼

4

確認的UpdateProgress 'DisplayAfter' 設置爲1000(1秒)

+0

DisplayAfter在我的情況下是缺少的。我在更新面板中有更新進度面板,工作正常。感謝提示 – 2012-09-27 16:42:52

-1
Create a new ASP.NET Ajax-Enabled Web Site and then paste these code in ascs and aspx file. Run it and you can see the update progress. You can use animated gif files too to show the progress... 

ascx Page 
====================================================== 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>UpdateProgress control</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
     <asp:UpdateProgress runat="server" id="PageUpdateProgress" AssociatedUpdatePanelID="Panel"> 
      <ProgressTemplate> 
       Loading... 
      </ProgressTemplate> 
     </asp:UpdateProgress> 
     <asp:UpdatePanel runat="server" id="Panel"> 
      <ContentTemplate> 
       <asp:Button runat="server" ID="UpdateButton" OnClick="UpdateButton_Click" Text="Update" /> 
      </ContentTemplate> 
       <Triggers> 
        <asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click" /> 
       </Triggers>    
     </asp:UpdatePanel> 
    </form> 
</body> 
</html> 

aspx Page 
====================================================== 
protected void UpdateButton_Click(object sender, EventArgs e) 
{ 
    System.Threading.Thread.Sleep(5000); 
} 
1

我也有與沒有的UpdateProgress顯示問題。結果發現回到服務器的速度實際上非常快,從來沒有時間顯示。添加一個Thread.Sleep(10000)幫助顯示了這個問題。