[CLOSED] Cant clean Textfield after Keymap

  1. #1

    [CLOSED] Cant clean Textfield after Keymap


    I,ve been trying to clean a Textfield after a KeyMap but It is not working. However if i do the same, from a Button with a Directevent it works perfect.

    Here is an example of my code:
    <%@ Page Title="Fabricacion Jhayber" Language="C#" AutoEventWireup="true" CodeBehind="LecturaNota.aspx.cs" Inherits="Fabricacion.LecturaNota" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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>Fabricacion Jhayber</title>
    <script type="text/javascript">
            var Alerta = function (keyCode, e) {
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />           
            <ext:Panel ID="Panel1" runat="server">
                <ext:Window ID="Window1" runat="server" Closable="false" Resizable="false"
                Draggable="false" Modal="true"
                BodyPadding="5" Layout="columnlayout" cls="Windownotas" Width ="400" Hidden="false ">
                          <ext:Panel ID="PanelPrincipal" runat="server" AnchorHorizontal="100%"
                                Title="Lectura Nota" Margins="5" Padding="5" Region="Center" AnchorVertical="100%" Layout="FormLayout">
                                    <ext:FieldContainer ID="Codebarfield" runat="server" Layout="HBoxLayout" AnchorHorizontal="100%" >
                                            <ext:FieldSet ID="FieldSet1" runat="server" width="360" Title="Código Nota Terminado" MarginSpec="0 0 0 0">
                                                    <ext:Parameter Name="LabelWidth" Value="50" />
                                                    <ext:TextField ID="CodebarText" runat="server" FieldLabel="Código" width="300"/>
                        <ext:Button runat="server" >
                                <Click OnEvent="TestText"></Click>
            <ext:KeyMap runat="server" Target="={Ext.getBody()}">
                    <ext:KeyBinding Handler="Alerta" >
                            <ext:Key Code="ENTER" />
    using System;
    using System.Collections.Generic;
    using Persistencia.Dto;
    using Persistencia.Dao;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using Negocio;
    using System.Configuration;
    using Ext.Net;
    namespace Fabricacion
        public partial class LecturaNota : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
            public void LecturaCodeBar()
                CodebarText.Text = "";
            protected void TestText(object sender, EventArgs e)
                CodebarText.Text = "";
    Is there any way to do this? Thank You
    Last edited by fabricio.murta; Dec 06, 2018 at 3:18 PM.
  2. #2
    Hello @PascuV!

    Just by looking at the code I can see you are using Alerta as a Handler body. This is not supposed to work. You are missing the call's parens and (optionally) semicolon.

    My guess here is you should just change your keybinding's handler to Alerta();.

    I will just double check this guess, if I don't post back in some minutes, that's because my guess proved correct.
    Fabrício Murta
    Developer & Support Expert
  3. #3

    Your code seems to work, with or without the parenthesis to make the call. The problem in your test case specifically is just that browsers inherently tend to submit forms on enter key press whenever these forms contains but one HTML input field in the form's block.

    To prevent this, all that you can do is just preventDefault() of the key event. This issue has already been raised in this thread: Disable AutoPostBack, which, in turn, boiled down to adding another field to the form.

    There was another solution provided there that was later edited out. With that on mind, I've searched and found this stackoverflow thread that suggested a "generic" solution for the issue, which seems actual.

    To "translate" this to Ext.NET, one option would be to change your key binding Handler property to:

    <ext:KeyBinding Handler="this.lastKeyEvent.preventDefault(); Alerta();">
    As per the stackoverflow suggestion, this looks to be the best option, as the preventDefault() call should happen every time the key is hit in the browser.

    Hope this helps!
    Last edited by fabricio.murta; Dec 04, 2018 at 6:31 PM.
  4. #4
    Thank You so much Fabricio, Its working perfect now.
  5. #5
    Hello @PascuV!

    Thanks for the feedback, glad it helped!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] JS Error if KeyMap target doesnt exist
    By Z in forum 4.x Premium Help
    Replies: 6
    Last Post: Jul 14, 2017, 4:20 PM
  2. Replies: 6
    Last Post: Sep 04, 2012, 12:59 PM
  3. Replies: 4
    Last Post: Jul 25, 2012, 5:45 AM
  4. [CLOSED] Clean GridPanel
    By rnfigueira in forum 1.x Premium Help
    Replies: 1
    Last Post: Jul 18, 2011, 9:10 PM
  5. How to clean (really) a SelectionModel ?
    By eliezer in forum 1.x Help
    Replies: 4
    Last Post: Feb 06, 2009, 2:08 PM

Posting Permissions