2011-06-20 44 views
1

我相信我錯過了一些非常明顯的東西,但我看不到它。當最後一個項目被刪除時,ASP.NET面板不會更新

我有一個更新面板,裏面有一個datalist。數據列表中的每個項目都有一個刪除按鈕,我使用該按鈕爲該項目發出刪除命令。

缺失是一個兩部分的過程:我首先彈出的代碼隱藏模態對話,以尋求確認,像這樣:

/// <summary> 
/// Manager delete command 
/// </summary> 
protected void dlKeywordsManager_DeleteCommand(object source, DataListCommandEventArgs e) 
{ 
    //Get the subject ID 
    int keywordID = (int)dlKeywordsManager.DataKeys[e.Item.ItemIndex]; 

    //Remember the keyword ID on the modal popup 
    hfKeywordID.Value = keywordID.ToString(); 
    btnConfirmationPopupOK.CommandArgument = "Delete"; 

    lblConfirmationPopupMessage.Text = "キーワード「" + e.CommandArgument.ToString() + "」を本當に削除しますか?"; 

    mpConfirmationPopup.Show(); 
    dlKeywordsManager.DataBind(); 
    udpKeywordsManager.Update(); 
} 

此模式彈出也是更新面板內,這樣我可以得到在部分回傳時刷新標籤文本值。

當使用按下彈出我去執行的OK按鈕:

protected void btnConfirmationPopupOK_Click(object source, EventArgs e) 
{ 
     int keywordID = int.Parse(hfKeywordID.Value); 
     KeywordBLLOperation operationResult; 
     switch (((Button)source).CommandArgument) 
     { 
      case "Delete": 
       operationResult = keywordsAPI.DeleteKeyword(keywordID); 
       switch (operationResult.Result) 
       { 
        case KeywordBLLOperationResult.Deleted: 
         lnlNotificationsPopupMessage.Text = "キーワード「" + operationResult.KeywordName + "」を削除しました。"; 
         break; 
        case KeywordBLLOperationResult.Failed: 
         lnlNotificationsPopupMessage.Text = "キーワード「" + operationResult.KeywordName + "」の削除に失敗しました。アドミニストレーターにお伝えください。"; 
         break; 
       } 
       break; 
     } 
     mpNotificationPopup.Show(); 
     dlKeywordsManager.DataBind(); 
     udpKeywordsManager.Update(); 
} 

我這裏除去一些非必要線簡潔。

這裏是ASPX標記去與代碼:

<asp:UpdatePanel ID="udpKeywordsManager" runat="server" Visible="true" UpdateMode="Conditional" > 

<ContentTemplate> 

    <div class="keywordsManagerHeader"> 

     <%--DISPLAY STATISTICS--%> 
     <asp:CheckBox ID="chkShowUsageStatistics" runat="server" Text="參照回數を表示する" AutoPostBack="true" OnCheckedChanged="chkShowUsageStatistics_CheckedChanged" CssClass="keywordsManagerCheckBoxes" TextAlign="Left" /> 

     <%--DISPLAY ORDER--%> 
     <span class="keywordsManagerLabel" >並べ替え</span> 
     <asp:DropDownList ID="ddlKeywordsOrder" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlKeywordsOrder_SelectedIndexChanged" > 
      <asp:ListItem Text="なし" Value="None" /> 
      <asp:ListItem Text="科目名" Value="Name" /> 
      <asp:ListItem Text="參照回數" Value="Frequency" /> 
     </asp:DropDownList> 
     <asp:RadioButtonList ID="rdlOrder" runat="server" AutoPostBack="true" RepeatLayout="Flow" RepeatDirection="Horizontal" CssClass="keywordsManagerRadioButtons" Enabled="false" > 
      <asp:ListItem Text="昇順" Value="Ascending" /> 
      <asp:ListItem Text="降順" Value="Descending" /> 
     </asp:RadioButtonList> 

     <%--UPDATE PROGRESS INDICATOR--%> 
     <span style="position: absolute;"> 
      <asp:UpdateProgress ID="udpSubjectsManagerUpdateProgress" AssociatedUpdatePanelID="udpKeywordsManager" runat="server" DisplayAfter="500" DynamicLayout="False" > 
       <ProgressTemplate> 
        <img class="updateProgressIndicator" src="~/Library_Images/Animations/ajax_loading.gif" alt="" runat="server" /> 
       </ProgressTemplate> 
      </asp:UpdateProgress> 
     </span> 

    </div> 

    <div class="keywordsManagerContainer"> 

     <%--SUBJECTS DATALIST--%> 
     <asp:DataList ID="dlKeywordsManager" runat="server" DataKeyField="Keyword_ID" DataSourceID="dsBookKeywords" RepeatDirection="Horizontal" 
      OnItemDataBound="dlKeywordsManager_ItemDataBound" OnDeleteCommand="dlKeywordsManager_DeleteCommand" OnUpdateCommand="dlKeywordsManager_UpdateCommand" OnPreRender="dlKeywordsManager_PreRender" > 

      <ItemTemplate> 

       <span id="KeywordInfo" class="keywordsManagerItem" runat="server"> 
        <asp:Label ID="Subject_NameLabel" runat="server" Text='<%# Eval("Keyword_Name") %>' /> 
        <asp:Label ID="Subject_FrequencyLabel" runat="server" Text='<%# " (" + Eval("Frequency") + ")" %>' Visible="false" /> 
       </span> 

       <%--HOVER MENU PANEL--%> 
       <asp:Panel ID="pnlKeywordContextMenu" runat="server" CssClass="keywordsManagerPopupMenuOverall"> 

        <div class="keywordsManagerPopupMenuRow" > 
         <span class="keywordsManagerLabel">科目「</span> 
         <asp:Label ID="pnlSubjectContextMenu_Subject_NameLabel" runat="server" Text='<%# Eval("Keyword_Name") %>' /> 
         <span class="keywordsManagerLabel">」を參照している文書數:</span> 
         <asp:Label ID="pnlSubjectContextMenu_Subject_FrequencyLabel" runat="server" Text='<%# Eval("Frequency") %>' /> 
        </div> 

        <div ID="Book_ISO_NumbersList" class="keywordsManagerBookISONumbersList" runat="server" visible='<%# (string.IsNullOrEmpty(Eval("Book_ISO_Numbers").ToString())) ? bool.Parse("false") : bool.Parse("true") %>' > 
         <span class="keywordsManagerLabel">文書:</span> 
         <asp:Label ID="Book_ISO_Numbers_Label" runat="server" Text='<%# Eval("Book_ISO_Numbers") %>' /> 
        </div> 

        <div class="keywordsManagerPopupMenuSeparator"></div> 

        <div class="keywordsManagerPopupMenuRow" > 
         <asp:TextBox ID="Keyword_NameTextBox" runat="server" Text='<%# Eval("Keyword_Name") %>' CssClass="keywordsManagerPopupMenuInput" /> 
         <asp:Button ID="btnEdit" runat="server" Text="編集" CssClass="buttonShortBottom" CommandName="Update" CausesValidation="true" CommandArgument='<%# Eval("Keyword_Name") %>' /> 
         <asp:Button ID="btnDelete" runat="server" Text="削除" CssClass="buttonShort" CommandName="Delete" CommandArgument='<%# Eval("Keyword_Name") %>' /> 
        </div> 

       </asp:Panel> 

       <%--HOVER MENU EXTENDER--%> 
       <asp:HoverMenuExtender ID="hmeKeywordContextMenu" runat="server" TargetControlID="KeywordInfo" PopupControlID="pnlKeywordContextMenu" PopDelay="100" PopupPosition="Right" HoverDelay="100" /> 

      </ItemTemplate> 

      <SeparatorTemplate> 

       <span class="keywordsManagerItemSeparator"></span> 

      </SeparatorTemplate> 

     </asp:DataList> 

    </div> 

    <%--MODAL POPUPS--%> 
    <%--CONFIRMATION POPUP--%> 
    <asp:Panel ID="pnlConfirmationsPopup" runat="server" CssClass="modalNotificationOverall" > 
      <div class="modalNotificationRow"> 
       <asp:Label ID="lblConfirmationPopupMessage" runat="server" Text="" /> 
      </div> 
      <div class="modalNotificationRow"> 
       <asp:Button ID="btnConfirmationPopupOK" runat="server" Text="はい" CssClass="buttonMediumLong" OnClick="btnConfirmationPopupOK_Click" /> 
       <asp:Button ID="btnConfirmationPopupCancel" runat="server" Text="いいえ" CssClass="buttonMediumLong" /> 
      </div> 
     <asp:HiddenField ID="hfKeywordID" runat="server" /> 
     <asp:HiddenField ID="hfNewKeywordName" runat="server" /> 
     </asp:Panel> 
    <%--NOTIFICATION POPUP--%> 
    <asp:Panel ID="pnlNotificationsPopup" runat="server" CssClass="modalNotificationOverall" > 
      <div class="modalNotificationRow"> 
       <asp:Label ID="lnlNotificationsPopupMessage" runat="server" Text="" /> 
      </div> 
      <div class="modalNotificationRow"> 
       <asp:Button ID="btnNotificationsPopupOK" runat="server" Text="OK" CssClass="buttonMediumLong" /> 
      </div> 
     </asp:Panel> 
    <%--MODAL POPUP ANCHORS AND MODULES--%> 
    <%--DELETE CONFIRMATION--%> 
    <asp:Label ID="lblConfirmationPopupAnchor" runat="server" Text="" /> 
    <asp:ModalPopupExtender ID="mpConfirmationPopup" runat="server" TargetControlID="lblConfirmationPopupAnchor" PopupControlID="pnlConfirmationsPopup" BackgroundCssClass="modalNotificationBackground" CancelControlID="btnConfirmationPopupCancel" /> 
    <asp:Label ID="lblNotificationPopupAnchor" runat="server" Text="" /> 
    <asp:ModalPopupExtender ID="mpNotificationPopup" runat="server" TargetControlID="lblNotificationPopupAnchor" PopupControlID="pnlNotificationsPopup" BackgroundCssClass="modalNotificationBackground" CancelControlID="btnNotificationsPopupOK" /> 

</ContentTemplate> 

有很多標記的在那裏。結構如下:我有一個包含dropdownlist,radiobuttonlist等的標題部分,它允許我指定數據的排序(數據來自對象數據源)

我擁有包含項目的數據列表。每個項目都有一個hovermenuextender,在這個hovermenuextender中我有按鈕來發布編輯和刪除文件。

模式彈出窗口也位於更新面板內,但位於數據列表外部,因此可根據需要進行更新。

我的問題是,這個工作正常,只要我刪除的項目不是在數據專家留下的最後一個項目。如果它是最後一個彈出窗口(mpNotificationPopup)沒有顯示的最後一個項目。

代碼執行完畢,所以缺少項目必須導致upadte面板(udpKeywordsManager)不能更新?

任何有關如何在這種情況下獲取數據更新的幫助將是最受歡迎的。

在此先感謝。

+0

你能發佈UpdatePanel的標記代碼嗎? (其中的元素可能並不重要,但屬性和任何觸發器都會有用)。 –

+0

您:對,我應該在第一個位置添加標記。我現在已將標記添加到問題中。 –

+0

我剛剛在一個真正簡化的項目中再次測試了這個,它應該真的以我在這裏的方式工作...... –

回答

1

您應該向我們展示aspx標記,但也許您已在UpdatePanel中使用了ModalPopupExtender。嘗試將UpdatePanel以外的ModalPopupExtender的PopupControlID屬性ID設置爲div/Panel

您只需將UpdatePanel嵌套在Popup-Control的內部而不在其周圍。

我希望以下使它更清晰:

而不是做這種方式:

<UpdatePanel> 
    <DataList> 
    </DataList> 
    <ModalPopupExtender> 
    </ModalPopupExtender> 
</UpdatePanel> 

你應該做的是這樣的:

<ModalPopupExtender> 
    <UpdatePanel> 
     <DataList> 
     </DataList> 
    </UpdatePanel> 
<ModalPopupExtender> 
+0

嗨,謝謝你的回答。我不確定我是否正確地遵循你所說的話。你的意思是什麼,而不是我現在有,那就是: 我做的: ? 根本不刷新模式彈出窗口,所以我不能用它作爲確認對話這種方式... –

+0

@ user643192:我很高興你已經解決了你的問題。無論我編輯了我的答案,以更清楚地說明如何在ModalPopupExtender中嵌套UpdatePanel。 –

+0

啊,我明白你的意思了。當我僅更新模式彈出窗口時,這將節省我不得不刷新整個數據列表。更有效地進行模態彈出對話的方式。謝謝你的提示! –

1

回答我的問題。在痛苦地重建整個事情之後,我意識到當沒有任何項目時,我在數據列表的OnPreRender事件中將更新面板的可見性設置爲false。這基本上通過刷新中途關閉更新面板,所以當最後一個元素被刪除時頁面不刷新。

通過在更新面板中放置一個面板對其進行排序,該面板包含除「無信息」標籤之外的所有元素,並切換其可見性。對於這個愚蠢的問題抱歉,我想我在寫這段代碼時有一個愚蠢的時刻...

相關問題