Behavior change in radtextbox

4 posts, 0 answers
  1. Daniel
    Daniel avatar
    175 posts
    Member since:
    Feb 2009

    Posted 16 Jul 2009 Link to this post

    Hi. Has there been a change to the RadTextBox, where if you press the Enter key it fires the last button rendered on the page? I have some ClientEvents-OnKeyPress events that use to fire when the Enter key was pressed, but now it isn't working.

    function KeyEnterPeople(sender, eventArgs) {  
                var c = eventArgs.get_keyCode();  
                if (c == 13) {  
                    var peopleSearch = document.getElementById('ctl00_rdPeopleSearch_C_btnPeopleQuickSearch');  
                    peopleSearch.click();  
                }  
            } 

    <Telerik:RadTextBox ID="rtbPeopleQuickSearch" runat="server" Text="Firstname" Width="200px" Skin="Vista" ClientEvents-OnKeyPress="KeyEnterPeople" /> 

    Daniel
  2. Daniel
    Daniel avatar
    175 posts
    Member since:
    Feb 2009

    Posted 16 Jul 2009 Link to this post

    Sorry, I forgot to mention. I can replicate the problem by placing a RadTextBox and an ASP button on the same page and clicking into the RadTextBox also highlights the ASP button. Which in turn, by pressing the Enter key, it also presses the ASP button. This doesn't happen with a standard HTML input button.

    Daniel
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Daniel avatar
    175 posts
    Member since:
    Feb 2009

    Posted 16 Jul 2009 Link to this post

    Okay, talking to myself again... This also happens with a standard HTML input textbox. Sorry guys, just disregard these posts. This didn't happen with the previous Q1 2009 release of RadTextBox, weird.

    Daniel
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 20 Jul 2009 Link to this post

    Hi Daniel,

    I didn't try your approach - but I've a working one.
    First the code:
    function KeyPressed1(ctrl, e) {  
        HandleKeyPressed(ctrl, e, 'txtValue1');  
    }  
     
    function HandleKeyPressed(ctrl, e, txtButton) {  
        if (e.get_domEvent().rawEvent.keyCode == 8) {  
            return false;  
        }  
        if (e.get_domEvent().rawEvent.keyCode == 13) {  
            __doPostBack(ctrl._clientID.replace(txtButton, 'UpdateButton').replace(/_/g, "$"), '');  
            e.get_domEvent().preventDefault();  
            e.get_domEvent().stopPropagation();  
        }  
        if (e.get_domEvent().rawEvent.keyCode == 27) {  
            __doPostBack(ctrl._clientID.replace(txtButton, 'CancelButton').replace(/_/g, "$"), '');  
            e.get_domEvent().preventDefault();  
            e.get_domEvent().stopPropagation();  
        }  
    }  
     
    Let me explain the bit's a bit :)
    First my handler (on the RadTextBox) is attached to KeyPressed1 (I have more of those handlers).
    The reason for this "in between handler" - I need the ID of the button. (Of course I could get it via code - but so it is easier).
    Now to the handler.
    The check for backspace is important - else it would result in a "browser back" when on beginning of the text field!!
    Next I check for enter an ESC.
    And than I use the even of the buttons.
    To have this working 3 things are needed:
    a.) an asp:button with the ID UpdateButton must exist
    b.) an asp:button with the ID CancelButton must exist
    c.) both buttons must exist a the same level as the RadTextBoxes.

    Point c.) is important because in the same level controls get the same "decoration" like for an example
    ctl00_cphContent_rgProdukte_ctl00_ctl07_txtValue_text
    That's about my code.

    You could give your code a try with the following changes:
    function HandleKeyPressed(ctrl, e) {  
        if (e.get_domEvent().rawEvent.keyCode == 8) {  
            return false;  
        }  
        if (e.get_domEvent().rawEvent.keyCode == 13) {  
            var peopleSearch = document.getElementById('ctl00_rdPeopleSearch_C_btnPeopleQuickSearch');     
                    peopleSearch.click();   
            e.get_domEvent().preventDefault();  
            e.get_domEvent().stopPropagation();  
        }  
    }  
     
    I guess (not sure) that the effects you get depend on event bubbling.

    Regards

    Manfred
Back to Top