onblur execute several times radtextbox

5 posts, 1 answers
  1. Gilberto
    Gilberto avatar
    15 posts
    Member since:
    Sep 2019

    Posted 25 Sep 2020 Link to this post

    Im using two radtextboxes within  GridTemplateColumns. Im trying to use an onblur event but when I make some tests for some reazon, the attached function is firing several times. What is causing this behavior?

    Aspx

    1.<telerik:GridTemplateColumn UniqueName="VisibleAccCode" HeaderText="Código Cuenta"
    2. HeaderStyle-HorizontalAlign="Center"
    3. ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="250px">
    4.         <ItemTemplate>
    5.                 <telerik:RadTextBox ID="TxtAccCode" runat="server" Width="85%"/>
    6.         </ItemTemplate>
    7.</telerik:GridTemplateColumn>
     

     

     

    VB
    01.
    Dim TxtAccCode As RadTextBox = CType(item.FindControl("TxtAccCode"), RadTextBox)
    02.Dim TxtAcctName As RadTextBox = CType(item.FindControl("TxtAcctName"), RadTextBox)
    03. 
    04.Dim sJsFunction As String
    05. 
    06.sJsFunction = "function (s,a){BuscarAccCode(s,a," & RowIndex & ");}"
    07. 
    08.If TxtAccCode IsNot Nothing Then
    09.        TxtAccCode.ClientEvents.OnBlur = sJsFunction
    10.End If
    11. 
    12.sJsFunction = "function (s,a){BuscarAccName(s,a," & RowIndex & ");}"
    13. 
    14.If TxtAcctName IsNot Nothing Then
    15.         TxtAcctName.ClientEvents.OnBlur = sJsFunction
    16.End If

     

    Jscript

    1.function BuscarAccCode(sender, eventArgs, rowIndex) {
    2.            alert(sender.get_id() + ' index ' + rowIndex);
    3.        }
    4. 
    5.function BuscarAccName(sender, eventArgs, rowIndex) {
    6.            alert(sender.get_id() + ' index ' + rowIndex);
    7.        }
  2. Doncho
    Admin
    Doncho avatar
    95 posts

    Posted 30 Sep 2020 Link to this post

    Hi Gilberto,

    I couldn't spot an obvious cause for the described problematic behavior.

    I have created a basic sample project based on the provided code. I have switched the alert to console.log() in the event listener for more convenient tracking of the results. On my side, it behaves as expected. Please give a try to the sample to see how it works on your end. (To run it you will need to place the Telerik.Web.UI.dll and Telerik.Web.UI.xml in the bin folder.)

    It would be very helpful if you provide us the steps to replicate the issue with the sample. 

    Kind regards,
    Doncho
    Progress Telerik

    Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

  3. Gilberto
    Gilberto avatar
    15 posts
    Member since:
    Sep 2019

    Posted 30 Sep 2020 in reply to Doncho Link to this post

    hello. I realized the problem occurs when I have more than one textbox template. Plase, add a second textbox template and use an alert instead of using console logs. I modified you example and I was able to reproduce the issue.
  4. Answer
    Doncho
    Admin
    Doncho avatar
    95 posts

    Posted 30 Sep 2020 Link to this post

    Hi Gilberto,

    Could you please clarify if the issue is occurring only when calling the alert() method? Is the event fired twice when logging it on the console?

    Since the alert of the browser moves the focus out of the control there is a possibility that you run into a loop.
    Something like the one below - http://somup.com/cYQvodl6xQ

    <script>
        function myFunction() {
            alert("blurr");
        }
    </script>
    <asp:TextBox ID="TextBox1" runat="server" onblur="myFunction()"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" onblur="myFunction()"></asp:TextBox>

    Regards,
    Doncho
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  5. Gilberto
    Gilberto avatar
    15 posts
    Member since:
    Sep 2019

    Posted 30 Sep 2020 in reply to Doncho Link to this post

    You are right, Doncho. It only happens with alert. I changed to console logs and everything is working fine. thank you very very much!!!!

Back to Top