从外部按钮触发时,更新面板内的Formview不会更新

时间:2014-01-04 19:28:12

标签: asp.net asp.net-ajax

我在更新面板中有一个formview但没有任何反应:

<asp:Panel ID="uploadpanel" runat="server" CssClass="rightblock" Width="480px">
  <asp:UpdatePanel id="upnlGvAdmins" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>    
       <asp:FormView ID="fvPhpto" runat="server" DataKeyNames="id"
          Width="480px" AllowPaging="True"
          PagerSettings-Visible="false">
          <ItemTemplate>
            <asp:Label Text='<%# Eval("title") %>' runat="server" ID="descriptionLabel" />
            <asp:mageID="thumb1" runat="server" ImageSize="Large" PhotoID='<%# Eval("id") %>' />
            <asp:Label ID="noteslabel" runat="server" Text='<%#Eval("notes") %>' />
          </ItemTemplate>
       </asp:FormView>
     </ContentTemplate>
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="UploadFile" />
     </Triggers>
   </asp:UpdatePanel>

   <h3>Upload Photo</h3>
   <asp:FileUpload ID="FileUpload1" runat="server" CssClass="txtfield" />
   <div class="actionbuttons">
      <asp:LinkButtn ID="UploadFile" runat="server" Text="Upload" OnClick="UploadFile_Click" />
    </div>
 </asp:Panel>

1 个答案:

答案 0 :(得分:1)

今天我遇到了同样的问题。按钮上的CommandName="Insert"不够,我无法获取表单视图来执行更新。我可以解决它的唯一方法是取消更新面板并通过完全回发(boo!)或使用我的按钮的OnClick事件手动触发表单视图更新。它仍然不理想,但它的工作原理。

所以,在aspx中我有这个:

<asp:UpdatePanel runat="server" ID="upMain" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
           <asp:FormView runat="server" ID="fvNewForm" DataSourceID="dsoJobForm" DefaultMode="Insert">
            <InsertItemTemplate>
                <h3>Create a new job form</h3>
                <div class="subSet">
                    Job Form ID: &nbsp;
                <asp:TextBox runat="server" ID="txtJobFormID" MaxLength="10" Width="100"></asp:TextBox><br />
                    <br />
                    Job Form Name:<br />
                    <asp:TextBox runat="server" ID="txtJobFormName" MaxLength="50"></asp:TextBox><br />
                    <br />
                    <asp:Button runat="server" ID="btnSaveNewForm" CommandName="Insert" OnClick="TriggerFVUpdate" Text="Save & Continue" />
                </div>
            </InsertItemTemplate>

        </asp:FormView>

    </ContentTemplate>
</asp:UpdatePanel>

在后面的代码中,我有这个:

Protected Sub TriggerFVUpdate(sender As Object, e As EventArgs)
    Me.fvNewForm.InsertItem(True)
End Sub

如果有人有更好的解决方案,我完全赞成了,所以请告诉我!