This is a migrated thread and some comments may be shown as answers.

OnClientEntryAdded runs twice

6 Answers 110 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 21 Nov 2012, 03:32 PM
Hello!

I found out that OnClientEntryAdded handler runs twice when AllowCustomEntry="true", which is somewhat undesirable behavior. There's a simple reproduction below. One should put a breakpoint in ClientEntryAdded() and in ServerEntryAdded(). The consequence of steps is
1) ClientEntryAdded()
2) ServerEntryAdded()
3) ClientEntryAdded()


Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestFocusOnAutocomplete._Default" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2012.3.1120.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" 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">
 
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ClientEntryAdded(sender, eventArgs) {           
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager runat="server" />
        <telerik:RadAutoCompleteBox runat="server"
                                    AllowCustomEntry="true"
                                    OnClientEntryAdded="ClientEntryAdded"
                                    OnEntryAdded="ServerEntryAdded"
                                    ID="racb" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs
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;
using System.Threading;
 
namespace TestAutocomplete
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            racb.DataSource = new List<string>();
            racb.DataBind();
        }
 
        protected void ServerEntryAdded(object sender, AutoCompleteEntryEventArgs e)
        {
        }
    }
}







6 Answers, 1 is accepted

Sort by
0
Ron
Top achievements
Rank 1
answered on 21 Nov 2012, 03:34 PM
I forgot to mention an important detail: try to type in an arbitrary string (e.g. custom token) and press ';' (semicolon) to reproduce the behavior. AFAIK, semicolon means "submission" of a token.
0
Ron
Top achievements
Rank 1
answered on 21 Nov 2012, 03:39 PM
Pressing "Enter" instead of semicolon reproduces the behavior as well.
0
Nencho
Telerik team
answered on 26 Nov 2012, 01:10 PM
Hi Vakhtang,

I have performed some test, trying to replicate the experienced behavior, but to no avail. I have prepared a sample project for you, demonstrating the behavior at my end. In addition, I have recorded a video on the matter.
If the issue persists - could you modify the provided sample, in order to demonstrate us the described behavior at your end and send us the changed sample in a support ticket?
Please find the sample attached.


Greetings,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ron
Top achievements
Rank 1
answered on 27 Nov 2012, 11:36 AM
It's strange. The result of your code's work is correct: client and server event are only triggered once. But when in Visual Studio 2010 Premium SP1, debugger steps in

1) ClientEntryAdded()
2) ServerEntryAdded()
3) ClientEntryAdded()

as I described at first.
0
Ron
Top achievements
Rank 1
answered on 28 Nov 2012, 12:41 PM
Hi, Nencho.

I think I've prepared a clear reproduction. For the code below:
1) Add 'item0'. Browser console will show line

Wed Nov 28 16:34:52 UTC+0400 2012 ClientEntryAdded: item0

2) Add 'item1'. Browser console show _two_ lines
Wed Nov 28 16:35:46 UTC+0400 2012 ClientEntryAdded: item0

Wed Nov 28 16:35:46 UTC+0400 2012 ClientEntryAdded: item1
3) Add 'item2'. Browser console show _three_ lines
Wed Nov 28 16:36:39 UTC+0400 2012 ClientEntryAdded: item0

Wed Nov 28 16:36:39 UTC+0400 2012 ClientEntryAdded: item1

Wed Nov 28 16:36:39 UTC+0400 2012 ClientEntryAdded: item2 

4) _Remove_ 'item2' by clicking the cross within token. Console shows

Wed Nov 28 16:37:39 UTC+0400 2012 ClientEntryAdded: item0

Wed Nov 28 16:37:39 UTC+0400 2012 ClientEntryAdded: item1

but I haven't really added anything.

Your code displayed expected data in the previous example because of a postback that erased intermediate results on the page.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication9_1._Default" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2012.3.1127.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html>
 
<head id="Head1" runat="server">
</head>
<body>
    <form id="frmProductCatalogData" runat="server">
 
        <asp:ScriptManager runat="server" />
        <telerik:RadAutoCompleteBox runat="server"
                                    OnClientEntryAdded="ClientEntryAdded"
                                    AllowCustomEntry="true"
                                    OnEntryAdded="ServerEntryAdded"
                                    ID="racb" />
        <br />
        Server side event test label:
        <asp:Label ID="lbl" runat="server"></asp:Label>
        <br />
        Client-side event test input
        <input type="text" id="clientSelectedEntriesTexts" />
    </form>
    <script type="text/javascript">
        function ClientEntryAdded(sender, eventArgs) {
            var input = document.getElementById('clientSelectedEntriesTexts');
            input.value += eventArgs.get_entry().get_text();
            try {
                console.log(new Date().toString() + ' ClientEntryAdded: ' + eventArgs.get_entry().get_text());
            } catch (e) { }
        }
    </script>
</body>
</html>

Default.aspx.cs
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 WebApplication9_1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<string> ds = new List<string>();
 
            for (int i = 0; i < 4; i++)
            {
                string item = "item" + i.ToString();
                ds.Add(item);
            }
 
            racb.DataSource = ds;
            racb.DataBind();
        }
 
        protected void ServerEntryAdded(object sender, AutoCompleteEntryEventArgs e)
        {
            lbl.Text += e.Entry.Text;
        }
 
    }
}






0
Nencho
Telerik team
answered on 30 Nov 2012, 09:30 AM
Hi Vakhtang,

Please take a look at this forum thread where your question on a similar issue has been answered.


Greetings,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
AutoCompleteBox
Asked by
Ron
Top achievements
Rank 1
Answers by
Ron
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or