ASP.NET - 触发asyncpostback与里面的LinkButton的ListView这是里面的UpdatePanel [英] ASP.NET - Triggering asyncpostback with LinkButton inside ListView which is inside UpdatePanel
问题描述
好吧我的第一篇文章,我希望标题是有道理的。
Ok my first post and i hope the title makes sense.
我有一个UpdatePanel,和里面居住与一个按钮FileUpload控件来触发上传。下面,我有这是在隐藏文件databinded与上传文件的列表一个ListView。在UpdatePanel有一个PostBackTrigger指着上传按钮。
I have an updatepanel, and inside it resides a fileupload control with a button to trigger an upload. Beneath that i have a ListView which is databinded in the behind file with a list of files that is uploaded. The updatepanel has a "PostBackTrigger" pointed to the upload button.
所有这些工作只是因为它应该。对于列出的每个项目,有它删除该特定文件一个LinkButton。这也适用,因为它应该,但这里的东西:
它不会触发回传和Web搜索更不用说计算器的答案后,我试过无数方法。我尝试了很多,但没有真正发生,即使是什么样子的最佳解决方案的实施。
All of this works just as it should. For each item that is listed, there is a linkbutton which deletes that specific file. That also works as it should BUT here is the thing: It does not trigger a postback and i tried numerous methods after searching the web and not to mention stackoverflow for answers. I tried a lot but nothing really happens even if what looks like the best solution is implemented.
在ASCX文件(是其如果该事项一个用户控件):
The ascx file (yes its a usercontrol if that matters):
<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> </td>
<td>Du har ikke uploadet filer endnu.</td>
<td> </td>
</tr>
</EmptyDataTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="ButtonUploadFile" />
<asp:AsyncPostBackTrigger ControlID="ListViewDocuments" EventName="ItemCommand" />
</Triggers>
(注意asyncpostbacktrigger仅仅是另一种解决方案我尝试了,我也不会被删除。另外一个ScriptManager是present,它只是不会再$ P $上面code psented)
(Note the asyncpostbacktrigger is just another solution i tried out which i have not removed. Also a scriptmanager is present, it is just not represented in the above code)
从隐藏文件的ListViewDocuments_ItemCommand:
The ListViewDocuments_ItemCommand from the behind file:
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();
}
}
所以,就像我说的,在技术上一切正常,但在短期LinkButton的不刷新UpdatePanel的。
So like i said, technically everything works, but in short the linkbutton does not refresh the updatepanel.
如果有其他code段有任何疑问或需要,我会及时respondt。
If there is any questions or need for other code snippets, i will respondt promptly.
感谢您提前。
推荐答案
这有可能是在的CommandName =删除
是提高事件 ItemDeleted
和 ItemDeleting
,而不是 ItemCommand
。虽然我不得不说,如果是这样的话那么我期望的页面崩溃由于缺乏这些事件(见的 MSDN 了解详细信息)。
It's possible that the CommandName="Delete"
is raising the events ItemDeleted
and ItemDeleting
and not ItemCommand
. Although I have to say if this was the case then I would expect the page to crash due to the absence of those events (see MSDN for more details).
这是说,当我使用了删除(或编辑)字,因为我已经找到了问题的命令。所以我会尝试以下
That said when I have used the Delete (or Edit) word as a command I've found problems. So I would try the following
- 更改命令的名称类似
的CommandName =ItemDelete
。请问ListViewDocuments_ItemCommand
火现在 - 此外 - 看它是否是造成问题,我会暂时删除它,直到你确信该项命令触发,只要你想更新面板。
- Change the name of the command to something like
CommandName="ItemDelete"
. Does theListViewDocuments_ItemCommand
fire now - Also - to see if it is the update panel causing problems I would temporarily remove it until you are convinced that the item command fires as you want.
希望它可以帮助一些
这篇关于ASP.NET - 触发asyncpostback与里面的LinkButton的ListView这是里面的UpdatePanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!