OnClientEntryAdded runs twice

7 posts, 0 answers
  1. Zhanna Gultaeva
    Zhanna Gultaeva avatar
    33 posts
    Member since:
    Jan 2009

    Posted 21 Nov 2012 Link to this post

    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)
            {
            }
        }
    }







  2. Zhanna Gultaeva
    Zhanna Gultaeva avatar
    33 posts
    Member since:
    Jan 2009

    Posted 21 Nov 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Zhanna Gultaeva
    Zhanna Gultaeva avatar
    33 posts
    Member since:
    Jan 2009

    Posted 21 Nov 2012 Link to this post

    Pressing "Enter" instead of semicolon reproduces the behavior as well.
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 26 Nov 2012 Link to this post

    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.
  6. Zhanna Gultaeva
    Zhanna Gultaeva avatar
    33 posts
    Member since:
    Jan 2009

    Posted 27 Nov 2012 Link to this post

    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.
  7. Zhanna Gultaeva
    Zhanna Gultaeva avatar
    33 posts
    Member since:
    Jan 2009

    Posted 28 Nov 2012 Link to this post

    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;
            }
     
        }
    }






  8. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 30 Nov 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017