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

onblur execute several times radtextbox

4 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gilberto
Top achievements
Rank 1
Veteran
Gilberto asked on 26 Sep 2020, 02:58 AM

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

4 Answers, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 30 Sep 2020, 03:07 PM

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).

0
Gilberto
Top achievements
Rank 1
Veteran
answered on 30 Sep 2020, 03:22 PM
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.
0
Accepted
Doncho
Telerik team
answered on 30 Sep 2020, 03:51 PM

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/.

0
Gilberto
Top achievements
Rank 1
Veteran
answered on 30 Sep 2020, 03:56 PM

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

Tags
Grid
Asked by
Gilberto
Top achievements
Rank 1
Veteran
Answers by
Doncho
Telerik team
Gilberto
Top achievements
Rank 1
Veteran
Share this question
or