2009-10-15 200 views
3

無論出於何種原因 - 我的更新面板未更新。現在請注意,這是所有在GridView中的模板字段的項目模板內。主要嵌套。 幫助我,請UpdatePanel未更新

<ItemTemplate> 
    <asp:ImageButton ID="bttnEdit" runat="server" injid='<%# Eval("Id") %>' causeid='<%# Eval("Cause_Type") %>' natureid='<%# Eval("Nature_Type") %>' CausesValidation="False" ImageUrl="~/images/bttnEdit.gif" Text="Edit" OnClientClick ="loadmodal(this.injid,this.causeid,this.natureid);" /> 
    &nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
    CommandName="Delete" ImageUrl="~/images/bttnDelete.gif" Text="Delete" /> 
    <asp:Panel ID = "Pnlmodal" runat ="server" style="background-color:White; padding:1em 6px;"> 
     <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional" > 
     <Triggers> 
     <asp:AsyncPostBackTrigger ControlID ="bttnEdit" EventName ="Click" /> 
     </Triggers> 
     <ContentTemplate> 
      <asp:FormView ID="FormView2" runat="server" DefaultMode ="Edit" DataSourceID ="SqlDataSource8"> 
       <EditItemTemplate> 
        <table> 
        <tr> 
        <td colspan="2" align="center" style="color:Blue;font-size:large">Edit Injury</td> 
        </tr> 
        <tr><br /></tr> 
        <tr> 
         <td align="right" ><strong>What event caused the injury?</strong></td> 
         <td align="left"> 
          <asp:DropDownList ID="ddlcauseofinj" onchange="showifother('1');" runat="server" 
          DataSourceID="SqlDataSource2" DataTextField="Description" 
          DataValueField="ID" AppendDataBoundItems="True"> 
           <asp:ListItem Selected="True" style="color:gray" Value="0">Causes of Injury</asp:ListItem> 
          </asp:DropDownList> 
         </td> 
        </tr> 
        <tr id="trother1" style="display:none"> 
         <td align ="right"><strong>If Other, Please Describe:</strong></td> 
         <td align="left"> 
         <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"><strong>What is the extent of the Injury?</strong></td> 
         <td align="left"> 
          <asp:DropDownList ID="ddlextentofinj" runat="server" 
          onchange="showifother('2');" AppendDataBoundItems ="true" DataSourceID="SqlDataSource3" 
          DataTextField="Description" DataValueField="ID"> 
          <asp:ListItem Selected="True" style="color:gray" Value="0">Extent of the Injury</asp:ListItem> 
          </asp:DropDownList> 
         </td> 
        </tr> 
        <tr id="trother2" style="display:none"> 
         <td align="right"><strong>If Other, Please Describe:</strong></td> 
         <td align="left"> 
          <asp:TextBox ID="TextBox4" runat="server" TextMode="MultiLine" ></asp:TextBox> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"><strong>Type of Medical Treatment:</strong></td> 
         <td align ="left"> 
          <asp:DropDownList ID="DropDownList3" AppendDataBoundItems ="true" runat="server" 
          DataSourceID="SqlDataSource4" DataTextField="Description" DataValueField="ID"> 
          <asp:ListItem Selected="True" style="color:gray" Value="0">Medical Treatments</asp:ListItem> 
          </asp:DropDownList> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"><strong>Treatment Provider:</strong></td> 
         <td align="left"> 
          <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Injury_Desc")%>'></asp:TextBox> 
         </td> 
        </tr> 
        <tr> 
         <td colspan ="2" align="center"><asp:ImageButton ID="CancelButton" runat="server" ImageUrl="~/images/bttnCancel.gif" /></td> 
        </tr> 
        </table> 
       </EditItemTemplate> 
      </asp:FormView> 
     </ContentTemplate> 
     </asp:UpdatePanel> 
    </asp:Panel> 
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
    TargetControlID="bttnEdit" PopupControlID="Pnlmodal" 
    BackgroundCssClass="modalBackground" Drag="True" /> 
</ItemTemplate> 
+1

沒有更新面板的工作? – 2009-10-15 13:00:05

+0

你有沒有嘗試刪除ModalPopupExtender作爲一個測試...只是一個想法 – 2009-10-15 13:14:49

回答

0

感謝您的答案!我把整個面板移到了gridview和其他所有嵌套控件之外。有效。這是有問題找到控制ID的。

+1

在gridview內完成更新面板後,我不能說我同意這是正確的答案。我想你只是用斧頭打開門而不是門把手。兩者都完成相同的事情,但一個更有點hacky :) – JustLoren 2009-10-15 14:09:34

0

我猜你遇到與被點擊,而不是bttnEdit造成你的UpdatePanel刷新的問題,即使壽你有一個明確定義的觸發器。

如果出現這種情況,您可能會遇到問題,因爲您實際上並沒有爲bttnEdit定義服務器端單擊事件。相反,你用javascript來劫持點擊,並可能使用它來提交你的表單而不會傳遞給bttnEdit被點擊的服務器。

TL;博士:改變你的bttnEdit也做一個服務器端的點擊,或者改變你的UpdatePanel總是更新(第二個是一個醜陋的黑客)

+0

我改變它總是更新,但似乎並沒有更新。我有onclient點擊,因爲我設置一個變量的formview的數據源依賴的東西。所以我需要該updatepanel來更新。我已經在javascript中嘗試過dopostback,但它只是重新加載整個頁面。 – Eric 2009-10-15 13:00:05

+0

你可以有一個onclientclick和一個onclick - 他們共存的原因。我只是建議你使用兩者,因爲這應該可以解決你的問題。 – JustLoren 2009-10-15 14:07:57

1

我只是包住整個現場周圍的更新面板。這通常會訣竅。在網格視圖中有一個更新面板的事實可能會擾亂面板的ID並導致其不更新。

  1. 只是包裝在GridView在面板

  2. 嘗試整個網站

+3

如果你不關心性能,用updatepanel包裝整個頁面是很好的。就個人而言,我UpdateMode =條件所有我的更新面板,並只包裝適當的部分。 – JustLoren 2009-10-15 14:06:54