UpdatePanel未更新

时间:2009-10-15 12:47:53

标签: c# asp.net ajax gridview updatepanel

无论出于何种原因 - 我的更新面板没有更新。现在请注意,这都在gridview内的模板字段的项目模板中。主要嵌套。 帮帮我,

<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>

3 个答案:

答案 0 :(得分:1)

我只是将更新面板包裹在整个站点周围。这种接缝通常可以解决问题。您在网格视图中有更新面板的事实可能会弄乱面板的ID并导致它不更新。

  1. 只需在面板中包装gridview

  2. 尝试整个网站

答案 1 :(得分:0)

我猜你在点击bttnEdit时遇到问题,并且没有导致你的UpdatePanel刷新,即使你有明确定义的触发器。

如果是这种情况,那么问题就在于你实际上没有为bttnEdit定义服务器端点击事件。相反,你用javascript劫持了点击,并且可能使用它来提交你的表单,而不会传递到点击bttnEdit的服务器。

tl; dr:将您的bttnEdit更改为也进行服务器端点击,或者将您的更新面板更改为始终更新(第二个是丑陋的黑客攻击)

答案 2 :(得分:0)

感谢您的所有答案!我将整个面板移动到gridview和所有其他嵌套控件之外。有效。它找到了控制ID的问题。