Hello All,

I need to have a specific button pressed when a user finishes entering text and presses enter (while still focused on the textbox) in order to initiate a filter on a list.

I am capturing keypresses and recognizing when enter is pressed, the problem is, the last character is striped from the textbox before the behind code does the search *UNLESS* I run in debug mode and set a breakpoint in the javascript function - if I do that it works perfectly.

I am using Visual Studio 2005, the behind code is in C# and I am using javascript to capture key presses...

(in the .aspx file)

Code:
<radI:RadTextBox ID="unitRadTextBox" runat="server" LabelCssClass="radLabelCss_Default" Skin="Office2007" Width="125px"></radI:RadTextBox>
Code:
<asp:Button runat="server" ID="findButton" BorderWidth="1px" BackColor="Silver" Text="Find" BorderStyle="Ridge" CausesValidation="False" OnClick="findButton_Click" OnClientClick="enableShowAllButton()"></asp:Button>

(in the C# file)

Code:
protected void Page_Load(object sender, EventArgs e){
    ...
    unitRadTextBox.Attributes.Add("onKeyPress", "catchEnterKey('" + findButton.ClientID + "', this, '" + unitRadTextBox.ClientID + "', event, '"+ Application +"')");
}

(in the javascript file)

Code:
// the following points the enter key to the correct button to click.
function catchEnterKey(findButton, textbox, findTextbox, mozEvent, application){
     var key;
     key = window.event.keyCode;
     if (key == 13){
        //Get the button the user wants to have clicked
        var btn = document.getElementById(findButton);
        btn.click();
        event.keyCode = 0;
    }
}
Note: I also have this in my javascript file:

Code:
// the following catches all key presses and stops backspace from causing the browser to go to the previous page
document.onkeydown = keyCatcher;
function keyCatcher() {
    var e = event.srcElement.tagName;

    if (event.keyCode == 8 && e != "INPUT" && e != "TEXTAREA") {
        event.cancelBubble = true;
        event.returnValue = false;
    }
}
Any insight is much appreciated!

Dave.