我在更新面板中有一个列表视图,但是我无法正确更新它 - 每个项目都有一个按钮可以将其从列表中删除 - 它可以执行此操作,但需要按两次按钮才能看到项目从页面中消失。
这里是标记:
<asp:ScriptManager ID="DashScriptManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="ToDoUpdate" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListView ID="ToDo" runat="server">
<ItemTemplate>
<li style="" class="<%# Eval("ToDoPriority")%>">
<%# Eval("ToDoText")%>
<div class="agile-detail">
<asp:LinkButton ID="ToDoComplete" runat="server" CssClass="pull-right btn btn-xs btn-primary" Text="Done" OnClick="ToDoComplete_Click"></asp:LinkButton>
<i class="fa fa-clock-o"></i> <%# Eval("ToDoDate")%>
</div>
</li>
<asp:HiddenField ID="HiddenToDoID" runat="server" Value='<%# Eval("ToDoId") %>' />
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
守则背后:
protected void ToDoComplete_Click(Object sender, EventArgs e)
{
LinkButton ToDoComplete = sender as LinkButton;
HiddenField todo = ToDoComplete.NamingContainer.FindControl("HiddenToDoID") as HiddenField;
int TodDoId = Convert.ToInt32(todo.Value);
DashboardController.UpdateToDo(TodDoId);
GetToDoItems(1);
ToDoUpdate.Update();
}
按一下按钮有没有办法做到这一点?
答案 0 :(得分:1)
您缺少的是UpdatePanel中的“触发器”部分。作为UpdateMode =“Conditional”的更新面板,您需要指定触发器。如果您使用正常的完整回发,则将AsyncPostBackTrigger更改为PostBackTrigger。
<asp:UpdatePanel ID="ToDoUpdate" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListView ID="ToDo" runat="server">
<li style="" class="<%# Eval("ToDoPriority")%>">
<%# Eval("ToDoText")%>
<div class="agile-detail">
<asp:LinkButton ID="ToDoComplete" runat="server" CssClass="pull-right btn btn-xs btn-primary" Text="Done" OnClick="ToDoComplete_Click"></asp:LinkButton>
<i class="fa fa-clock-o"></i> <%# Eval("ToDoDate")%>
</div>
</li>
<asp:HiddenField ID="HiddenToDoID" runat="server" Value='<%# Eval("ToDoId") %>' />
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ToDo" EventName="Click" />
</Triggers>
</asp:UpdatePanel>