gpt4 book ai didi

c# - RadListView ItemCommand 未触发

转载 作者:行者123 更新时间:2023-11-30 18:03:01 26 4
gpt4 key购买 nike

我有一个 RadListView 和一个绑定(bind)到 lstGameWaypoints_ItemCommand 的事件处理程序,如下所示。在第一次显示网格时,单击删除按钮成功触发回发和 ItemCommand 触发。

一旦回发完成,事件处理程序似乎不会再次连接,单击删除按钮不会导致任何操作发生。

有没有人以前遇到过类似的问题?

<telerik:RadListView runat="server" ID="RadListView1" 
DataSourceID="ObjectDataSource1" AllowPaging="true"
OnDataBound="lstGameWaypoints_DataBound"
OnItemCreated="lstGameWaypoints_ItemCreated"
OnItemCommand="lstGameWaypoints_ItemCommand">
<EmptyDataTemplate>
<div style="width: 100px;margin: 10px auto auto auto;"><button class="AddWaypoint">Add Waypoint</button></div>
</EmptyDataTemplate>
<ItemTemplate>
<td>
<table style="border:1px solid black;width: 232px;height: 70px;margin:auto;">
<tr>
<td>
Time:
</td>
<td>
<%# string.Format("{0:h:mm tt}", Eval("DateTime")) %>
</td>
</tr>
<tr>
<td>
Date:
</td>
<td>
<%# string.Format("{0:d}", Eval("DateTime")) %>
</td>
</tr>
<tr>
<td>
Chip Stack:
</td>
<td>
<%# string.Format("{0:C}", Eval("ChipStack")) %>
</td>
</tr>
<tr>
<td>
Notes:
</td>
<td>
<%# Eval("Notes") %>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:right;">
<asp:Button runat="server" ID="btnDelete" CssClass="deleteButton" CommandArgument='<%# Eval("WaypointID") %>' CommandName="Delete" Text="X" OnClientClick="return confirm('Are you sure you want to delete this waypoint?');" />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</telerik:RadListView>

protected void lstGameWaypoints_ItemCommand(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
//Do stuff
}
}

UPDATE:

这似乎是我用来托管此控件面板的 RadAjaxManager 的问题。如果我在面板上禁用 ajax,一切都会按预期进行。

这是一个完整的代码...

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> 
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="panGameWaypoints">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="panGameWaypoints" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="panGameDetails">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="panGameDetails" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
<ClientEvents OnRequestStart="RequestStart" OnResponseEnd="RequestEnd" />
</telerik:RadAjaxManager>

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="60">
<div class="loading">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/loading3.gif" AlternateText="loading" />
</div>
</telerik:RadAjaxLoadingPanel>

<asp:Panel runat="server" ID="panGameWaypoints" CssClass="GameWaypoints">
<table style="width:900px;margin:auto;">
<tr>
<telerik:RadListView runat="server" ID="lstGameWaypoints" AllowPaging="false"
OnDataBound="lstGameWaypoints_DataBound"
OnItemCreated="lstGameWaypoints_ItemCreated"
OnNeedDataSource="lstGameWaypoints_NeedDataSource">

<EmptyDataTemplate>
<div style="width: 100px;margin: 10px auto auto auto;"><button class="AddWaypoint">Add Waypoint</button></div>
</EmptyDataTemplate>
<ItemTemplate>
<td>
<table style="border:1px solid black;width: 232px;height: 70px;margin:auto;">
<tr>
<td>
Time:
</td>
<td>
<%# string.Format("{0:h:mm tt}", Eval("DateTime")) %>
</td>
</tr>
<tr>
<td>
Date:
</td>
<td>
<%# string.Format("{0:d}", Eval("DateTime")) %>
</td>
</tr>
<tr>
<td>
Chip Stack:
</td>
<td>
<%# string.Format("{0:C}", Eval("ChipStack")) %>
</td>
</tr>
<tr>
<td>
Notes:
</td>
<td>
<%# Eval("Notes") %>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:right;">
<asp:Button runat="server" ID="btnDelete" CssClass="deleteButton" CommandArgument='<%# Eval("WaypointID") %>' CommandName="Delete" Text="X" OnClientClick="return confirm('Are you sure you want to delete this waypoint?');" />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</telerik:RadListView>
</tr>
</table>
</asp:Panel>

最佳答案

我创建了一个小测试用例(包含在下面)以查看是否可以重现您的问题,您的实现与我的实现之间存在三个主要差异:

  1. 我没有指定 RadAjaxLoadingPanel
  2. 我没有指定任何 ClientEvents(即 RequestStartRequestEnd)
  3. 我没有使用 OnClientClick 确认对话框

解决方案 #1

在完成所有这些并将其添加到我的测试用例之后,我发现使用 RadAjaxManager 的确认对话框存在问题。一些研究提供了以下解决方案:

将您的 OnClientClick 代码更改为以下内容:

OnClientClick="if(!confirm('Are you sure you want delete this?')) return false;"

这能解决您的问题吗?

这里有一些关于这个问题的文档:
www.telerik.com/help/aspnet-ajax/ajax-confirmation.html


以上应该可以解决您的问题,但如果不能,请尝试暂时删除 RequestStartRequestEnd 客户端事件,并继续剥离“extras”,直到找到问题为止。

这是一个按预期工作的测试用例:

ASPX:

<telerik:RadAjaxManager ID="rda" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="pnlTest">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="pnlTest" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<asp:Panel ID="pnlTest" runat="server">
<telerik:RadListView ID="lst" runat="server" OnItemCommand="lst_Command" OnNeedDataSource="lst_NeedDataSource">
<ItemTemplate>
<%#Eval("Test")%>
<asp:Button ID="btnDelete" runat="server" CommandArgument='<%#Eval("Test")%>' OnClientClick="if(!confirm('Are you sure you want delete this?')) return false;" CommandName="Delete" Text="Test" />
</ItemTemplate>
</telerik:RadListView>
<asp:Label ID="lblCommandArg" runat="server"></asp:Label>
</asp:Panel>

代码隐藏:

protected void lst_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("Test", typeof(string));

DataRow row = table.NewRow();
row.SetField<string>("Test", "Testing");
table.Rows.Add(row);

row = table.NewRow();
row.SetField<string>("Test", "Testing again");
table.Rows.Add(row);

lst.DataSource = table;
}

protected void lst_Command(object sender, RadListViewCommandEventArgs e)
{
lblCommandArg.Text = e.CommandArgument.ToString();
}

使用 RadAjaxPanel 而不是 RadAjaxManager

查看您的代码,看起来最简单的解决方案可能是使用 RadAjaxPanel 而不是 RadAjaxManager。我不确定这是否适合您,但这可能是让您的代码正常工作的最简单方法。

panGameWaypoints 使用 RadAjaxPanel 而不是常规面板,这将确保其中包含的所有内容都将使用 AJAX:

<telerik:RadAjaxPanel ID="panGameWaypoints" runat="server">
<telerik:RadListView ID="RadListView1" runat="server" ... >
</telerik:RadAjaxPanel>

关于c# - RadListView ItemCommand 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7645125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com