【问题标题】:Formview inside updatepanel not updating when triggered from button outside当从外部按钮触发时,更新面板内的 Formview 不更新
【发布时间】:2014-01-04 19:28:11
【问题描述】:

我在更新面板中有一个表单视图,但没有任何反应:

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

【问题讨论】:

    标签: asp.net asp.net-ajax


    【解决方案1】:

    我今天也遇到了同样的问题。按钮上的CommandName="Insert" 不够用,我无法获取表单视图来执行更新。我可以解决它的唯一方法是关闭更新面板并通过完整的回发(嘘!)或使用我的按钮的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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 2014-06-18
      • 1970-01-01
      相关资源
      最近更新 更多