RadListView ItemCommand 未触发
我有一个 RadListView 以及一个绑定到 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
}
}
更新:
看来这是我用来托管该控件面板的 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>
I have a RadListView and also an event handler bound to lstGameWaypoints_ItemCommand as shown below. On First display of the grid clicking the delete button successfully triggers a postback and the ItemCommand firing.
Once the postback completes it appears that the event handlers are not being wired up again and clicking the delete button causes no action to occur.
Has anyone seen a similar issue before?
<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:
It appears that this is a issue with the RadAjaxManager that I am using to host the panel for this control. If I disable ajax on the panel, everything works as expected.
This is a full code...
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我创建了一个小测试用例(包含在下面)来看看是否可以重现您的问题,您的实现和我的实现之间存在三个主要区别:
RadAjaxLoadingPanel
ClientEvents
(即RequestStart
、RequestEnd
)OnClientClick
确认对话框Solution # 1
经过之后并将这些内容添加到我的测试用例中,我发现使用
RadAjaxManager
的确认对话框存在问题。一些研究提供了以下解决方案:将您的
OnClientClick
代码更改为以下内容:这可以解决您的问题吗?
以下是有关该问题的一些文档:
www.telerik.com/help/aspnet-ajax/ajax-confirmation.html
上面应该可以解决您的问题,但如果没有,请尝试暂时删除
RequestStart
和RequestEnd
客户端事件,并继续剥离“多余的”,直到找到问题为止。这是一个按预期工作的测试用例:
ASPX:
代码隐藏:
使用
RadAjaxPanel
而不是RadAjaxManager
查看您的代码,它看起来像最简单的解决方案可能是使用
RadAjaxPanel
而不是RadAjaxManager
。我不确定这是否适合您,但这可能是让您的代码正常工作的最简单方法。使用 RadAjaxPanel 作为
panGameWaypoints
而不是常规面板,这将确保其中包含的所有内容都将使用 AJAX:I created a little test case (included below) to see if I could reproduce your issue, and there were three main differences between your implementation and mine:
RadAjaxLoadingPanel
ClientEvents
(i.e.RequestStart
,RequestEnd
)OnClientClick
confirm dialogSolution #1
After going through and adding each of these to my test case, I discovered that there was an issue using a confirm dialog with the
RadAjaxManager
. A little research provided the following solution:Change your
OnClientClick
code to the following:Does this fix your issue?
Here's some documentation on the issue:
www.telerik.com/help/aspnet-ajax/ajax-confirmation.html
The above should fix your problem, but if not try temporarily removing the
RequestStart
andRequestEnd
client events, and continue to peel "extras" until you find the problem.Here is a test case that works as expected:
ASPX:
Code-behind:
Using
RadAjaxPanel
instead ofRadAjaxManager
Looking at your code, it looks like the easiest solution might be to use the
RadAjaxPanel
instead of theRadAjaxManager
. I'm not sure if this is an option for you, but that's probably the easiest way to get your code working.Use a RadAjaxPanel for
panGameWaypoints
instead of a regular Panel, which will ensure that everything contained within will use AJAX:您是否尝试将以下代码添加到 Page_Init 事件?
这应该在每次回发时挂钩您的事件。
Did you try to add following code to Page_Init event ?
This should hook your events on each postback.
我认为您需要告诉 RadAjaxManager 从自身更新列表...?这是没有意义的,但请尝试将其添加到您的 RadAjaxManager 中:
这样 RadListView 将重新连接它的事件。
I think you need to tell
RadAjaxManager
to update the list from itself...? That makes no sense but try adding this to yourRadAjaxManager
:That way the
RadListView
will rewire it's events.我不认为您需要添加
Use this 而不是上面
,而且我没有看到 lstGameWaypoints ItemCommand 事件已连接,您也可以使用 Itemcommand 的 OnItemDeleting 事件。
I don't thing you need to add
Use this instead of above
and i don't see lstGameWaypoints ItemCommand event is wired and you also can use OnItemDeleting event insted of itemcommand.
我认为问题出在您附加在 btnDelete 上的 OnClientClick 事件上。
我尝试模拟您的情况,并用 RadButton 替换了 Button(您处于 Telerik 环境中,对吧?),它公开了 OnClientClicking 事件。所以我创建了一个 js 函数:
并且我将 RadButton 设置为:
一切似乎都工作正常。
让我知道!
I think the problem is on the OnClientClick event you attached on the btnDelete.
I tried to simulate your situation, and I've replaced the Button with a RadButton (you're in a Telerik environment, right?), that expose the event OnClientClicking. So I've created a js function:
and I've setted the RadButton like:
All seems to work right.
Let me know!