在启用 AJAX 的 ASP.NET 页面中单击其他某个按钮时,Telerik RadListBox 控件会触发事件

发布于 2025-01-01 14:05:04 字数 4444 浏览 1 评论 0 原文

即使我单击页面中的按钮,RadListBox 将项目从源传输到目标也会被触发。我该如何阻止呢?

重现问题的步骤 – 加载页面。单击按钮。查看 AJAX 更新面板内列表框的项目计数。它将正确显示 – 分别为 7(源)和 0(目标)。将一项从源移动到目标 RadListBox。再次单击该按钮 – 它第一次显示 6(源)和 1(目标)。然后再次单击按钮 – 它显示 5(源)和 2(目标)..然后单击按钮..它显示 4(源)和 3(目标)。用户界面中没有任何变化。

我相信即使我单击按钮,从源到目标的传输事件也会被触发。单击按钮时如何停止 Transfer 事件?

在我的页面中,我必须刷新 AJAX 更新面板,但我不希望 RadListBox 中的项目同时发生更改。

ASPX 页面 -

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestRadListBox.WebForm1" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
     <title></title>
 </head>
 <body>
     <form id="form1" runat="server">
     <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
     </telerik:RadScriptManager>
     <div>
         <table>
             <tr>
                 <th colspan="2">Move 1 Item from Left to Right and then click the button below and see the Item Counts</th>
             </tr>
             <tr>
                 <td>
                     <telerik:RadListBox ID="SourceRadListBox" runat="server" Height="100px" Width="200px"
                         AllowTransfer="true" TransferToID="TargetRadListBox">
                     </telerik:RadListBox>
                 </td>
                 <td>
                     <telerik:RadListBox runat="server" ID="TargetRadListBox" Height="100px" Width="175px"
                         AllowReorder="true" />
                 </td>
             </tr>
         </table>
     </div>
     <br/>
     <div>
         Time OUTSIDE Update Panel : <asp:Label ID="timeOutsideLabel" runat="server"/>
     </div>
     <br/>
     <div align="left">
         <asp:Button ID="addRuleButton" runat="server" Text="Click To Refresh The Time Below Inside AJAX Update Panel" 
            onclick="addRuleButton_Click" />
     </div>
     <br/>
     <div>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
             <ContentTemplate>
             <table border = "2">
                 <tr><th>AJAX Update Panel</th></tr>
                 <tr><td>Time INSIDE Update Panel : <asp:Label ID="timeInsideLabel" runat="server"/></td></tr>
                 <tr><td>Item Count in Source RadListBox : <asp:Label ID="srcCount" runat="server"/></td></tr>
                 <tr><td>Item Count in Target RadListBox : <asp:Label ID="tarCount" runat="server"/></td></tr>
             </table>
             </ContentTemplate>
             <Triggers>
                 <asp:AsyncPostBackTrigger ControlID="addRuleButton" EventName="Click" />
             </Triggers>
         </asp:UpdatePanel>
     </div>
     </form>
 </body>
 </html>

C# 代码隐藏 -

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Telerik.Web.UI;

namespace TestRadListBox
 {
     public partial class WebForm1 : System.Web.UI.Page
     {
         protected void Page_Load(object sender, EventArgs e)
         {
             if (!IsPostBack)
             {
                 List<string> week = new List<string> { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
                 SourceRadListBox.DataSource = week;
                 SourceRadListBox.DataBind();
                 string timenow = DateTime.Now.ToLongTimeString();
                 timeInsideLabel.Text = timenow;
                 timeOutsideLabel.Text = timenow;
             }
         }

        protected void addRuleButton_Click(object sender, EventArgs e)
         {
             timeInsideLabel.Text = DateTime.Now.ToLongTimeString();
             srcCount.Text = SourceRadListBox.Items.Count.ToString();
             tarCount.Text = TargetRadListBox.Items.Count.ToString();
         }
     }
 }

RadListBox Transfer Items from Source to Destination is getting fired even when I click a button in the Page. How Do I stop That?

Steps to Reproduce the Issue – Load the Page. Click the button. See the Item counts for the List Boxes inside the AJAX Update Panel. It will show correctly – 7 (source) and 0 (target) respectively. Move one item from Source to Target RadListBox. Click the button again – it shows 6 (source) and 1 (target) for the first time. Then click the button again – it shows 5 (source) and 2 (target) ..then click button.. it shows 4 (source) and 3 (target). Nothing is changing in the User Interface.

I believe that Transfer event from source to target is getting fired even when I click the button. How do I stop the Transfer event when the button is clicked?

In my page, I have to refresh the AJAX Update panel but I do not want the items in the RadListBox to get changed at the same time.

ASPX Page -

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestRadListBox.WebForm1" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
     <title></title>
 </head>
 <body>
     <form id="form1" runat="server">
     <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
     </telerik:RadScriptManager>
     <div>
         <table>
             <tr>
                 <th colspan="2">Move 1 Item from Left to Right and then click the button below and see the Item Counts</th>
             </tr>
             <tr>
                 <td>
                     <telerik:RadListBox ID="SourceRadListBox" runat="server" Height="100px" Width="200px"
                         AllowTransfer="true" TransferToID="TargetRadListBox">
                     </telerik:RadListBox>
                 </td>
                 <td>
                     <telerik:RadListBox runat="server" ID="TargetRadListBox" Height="100px" Width="175px"
                         AllowReorder="true" />
                 </td>
             </tr>
         </table>
     </div>
     <br/>
     <div>
         Time OUTSIDE Update Panel : <asp:Label ID="timeOutsideLabel" runat="server"/>
     </div>
     <br/>
     <div align="left">
         <asp:Button ID="addRuleButton" runat="server" Text="Click To Refresh The Time Below Inside AJAX Update Panel" 
            onclick="addRuleButton_Click" />
     </div>
     <br/>
     <div>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
             <ContentTemplate>
             <table border = "2">
                 <tr><th>AJAX Update Panel</th></tr>
                 <tr><td>Time INSIDE Update Panel : <asp:Label ID="timeInsideLabel" runat="server"/></td></tr>
                 <tr><td>Item Count in Source RadListBox : <asp:Label ID="srcCount" runat="server"/></td></tr>
                 <tr><td>Item Count in Target RadListBox : <asp:Label ID="tarCount" runat="server"/></td></tr>
             </table>
             </ContentTemplate>
             <Triggers>
                 <asp:AsyncPostBackTrigger ControlID="addRuleButton" EventName="Click" />
             </Triggers>
         </asp:UpdatePanel>
     </div>
     </form>
 </body>
 </html>

C# Code Behind -

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Telerik.Web.UI;

namespace TestRadListBox
 {
     public partial class WebForm1 : System.Web.UI.Page
     {
         protected void Page_Load(object sender, EventArgs e)
         {
             if (!IsPostBack)
             {
                 List<string> week = new List<string> { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
                 SourceRadListBox.DataSource = week;
                 SourceRadListBox.DataBind();
                 string timenow = DateTime.Now.ToLongTimeString();
                 timeInsideLabel.Text = timenow;
                 timeOutsideLabel.Text = timenow;
             }
         }

        protected void addRuleButton_Click(object sender, EventArgs e)
         {
             timeInsideLabel.Text = DateTime.Now.ToLongTimeString();
             srcCount.Text = SourceRadListBox.Items.Count.ToString();
             tarCount.Text = TargetRadListBox.Items.Count.ToString();
         }
     }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文