-->

ASP.NET - 触发asyncpostback与LinkBut​​ton的内部的ListVie

2019-09-19 01:54发布

好吧我的第一篇文章,我希望标题是有道理的。

我有一个UpdatePanel,和里面居住与一个按钮FileUpload控件来触发上传。 下面,我有这是在隐藏文件databinded与上传文件的列表一个ListView。 在UpdatePanel有一个“PostBackTrigger”指出到上传按钮。

所有这一切工作只是因为它应该。 对于列出的每个项目,则其删除该特定文件一个LinkBut​​ton。 这也适用,因为它应该,但这里的东西:它不会触发回传,并在网上搜索后,我试过无数方法和更不用说计算器答案。 我尝试了很多,但没有真正发生,即使是什么样子的最佳解决方案的实施。

该ASCX文件(它是一个用户控件,如果该事项):

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
    <asp:Label ID="LabelUploadFile" runat="server" Text="Upload fil:"></asp:Label>
    <br />
    <asp:FileUpload ID="FileUploadDocument" runat="server" />
    <br />
    <asp:DropDownList ID="DropDownListDocumentType" runat="server"></asp:DropDownList>
    <br />
    <asp:Button ID="ButtonUploadFile" runat="server" Text="Upload fil" CssClass="nice small radius action button" onclick="ButtonUploadFile_Click" />
    <br />
    <br />
    <br />
    <asp:ListView ID="ListViewDocuments" runat="server" OnItemCommand="ListViewDocuments_ItemCommand">
        <LayoutTemplate>
            <table border="0" cellpadding="1">
                <tr>
                    <th align="left">Type</th>
                    <th align="left">Dokument</th>
                    <th></th>
                </tr>
                <tr id="itemPlaceholder" runat="server"></tr>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td><asp:Label runat="server" ID="lblName"><%#Eval("Type") %></asp:Label></td>
                <td><asp:Label runat="server" ID="lblType"><%#Eval("Dokument") %></asp:Label></td>
                <td><asp:LinkButton ID="DeleteButton" OnClientClick="return confirm('Slet dokument?');" CommandName="Delete" CommandArgument='<%# Eval("id")%>' runat="server" Text="Slet"></asp:LinkButton></td>
            </tr>
        </ItemTemplate>
        <EmptyDataTemplate>
            <tr>
                <td>&nbsp;</td>
                <td>Du har ikke uploadet filer endnu.</td>
                <td>&nbsp;</td>
            </tr>
        </EmptyDataTemplate>
    </asp:ListView>
</ContentTemplate>
<Triggers>
    <asp:PostBackTrigger ControlID="ButtonUploadFile" />
    <asp:AsyncPostBackTrigger ControlID="ListViewDocuments" EventName="ItemCommand" />
</Triggers>

(注意asyncpostbacktrigger只是另一种溶液我尝试了我还没有除去。另外一个ScriptManager存在时,它只是没有在上面的代码表示)

从隐藏文件的ListViewDocuments_ItemCommand:

protected void ListViewDocuments_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            //Send the file's ID to the data layer for deletion
            _talentDataAccess.DeleteTalentFileByFileId(Convert.ToInt32(e.CommandArgument));
            //Rebind the listveiw with a new list of files.
            _fillFileList();
        }
    }

所以,就像我说的,在技术上一切正常,但在短期LinkBut​​ton的不刷新的UpdatePanel。

如果有其他的代码片段有任何疑问或需要,我会及时respondt。

先感谢您。

Answer 1:

这有可能是CommandName="Delete"为提高事件ItemDeletedItemDeleting而不是ItemCommand 。 虽然我不得不说,如果是这样的话,那么我会预计的网页由于崩溃缺少这些事件(参见MSDN了解详细信息)。

这时候,我已经使用了删除(或编辑)字,因为我已经找到了问题的命令说。 所以我会尝试以下

  1. 该命令的名称更改为类似CommandName="ItemDelete" 。 是否ListViewDocuments_ItemCommand现在火
  2. 此外 - 看它是否是造成问题,我会暂时删除它,直到你确信该项命令火灾,只要你想更新面板。

希望它可以帮助一些



文章来源: ASP.NET - Triggering asyncpostback with LinkButton inside ListView which is inside UpdatePanel