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

Behavior change in radtextbox

3 Answers 110 Views
Input
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Iron
Daniel asked on 17 Jul 2009, 04:19 AM
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

3 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
Iron
answered on 17 Jul 2009, 04:33 AM
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
0
Daniel
Top achievements
Rank 1
Iron
answered on 17 Jul 2009, 04:40 AM
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
0
ManniAT
Top achievements
Rank 2
answered on 20 Jul 2009, 09:10 AM
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
Tags
Input
Asked by
Daniel
Top achievements
Rank 1
Iron
Answers by
Daniel
Top achievements
Rank 1
Iron
ManniAT
Top achievements
Rank 2
Share this question
or