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

RadTextBox postback problem

1 Answer 293 Views
Input
This is a migrated thread and some comments may be shown as answers.
Duy
Top achievements
Rank 1
Duy asked on 28 Apr 2009, 05:29 AM
Hi,

I implemented with RadTextBox, when it runs, I pressed "enter", it causes a post back event and it runs through all defined events of other components.  I tried to set the attribute autopostback to be true unfortunately it does not help as the standard textbox of visual studio does.

Cheers,

Duy

1 Answer, 1 is accepted

Sort by
0
ManniAT
Top achievements
Rank 2
answered on 28 Apr 2009, 12:50 PM
Hi,

with RadInput it is very simple to prevent such a thing - add a handler for KeyPress to it:
<telerik:RadNumericTextBox runat="server" ID="neNumValues" ClientEvents-OnKeyPress="KeyPressed"></telerik:RadNumericTextBox> 
And than handle this event in a simple script like this:
<script language="JavaScript" type="text/javascript">  
function KeyPressed(ctrl, e) {  
    if (e.get_domEvent().rawEvent.keyCode == 13) { //enter  
            //special handling (focus other control and so on) here  
            e.get_domEvent().preventDefault();  
            e.get_domEvent().stopPropagation();  
        }  
        if (e.get_domEvent().rawEvent.keyCode == 27) { // ESC  
            //special handling (clear values and so on) here  
            e.get_domEvent().preventDefault();  
            e.get_domEvent().stopPropagation();  
        }  
    }  
</script>  
 

If you do not handle Enter the event will "bubble up" - find a control (submit button or so) and this fires the postback.

HTH

Manfred
Tags
Input
Asked by
Duy
Top achievements
Rank 1
Answers by
ManniAT
Top achievements
Rank 2
Share this question
or