I have textboxes and each textbox contains search button beside that. On Key press i need to validate for alphanumeric characters and if Enter Key is pressed i need to Search. Right Now, My Textbox contains:
<asp:TextBox ID="txtId" runat="server" TabIndex="1" MaxLength="30" onkeypress="return validateAlphaNumeric(event, this);"></asp:TextBox>
Search Button:
<asp:ImageButton ID="imgSearch" runat="server" ImgUrl=".gif" OnClientClick="returnpassTxtboxValue(imgSearch);"/>
Now if i do:
If (event.KeyCode == 13) then SearchButton.Click();
This executes the returnpassTxtboxValue(imgSearch) function of Search button and then return back to textBox function validateAlphaNumeric() of Textbox. So my test fails by throwing parameterCount exception.
Javascript for textbox:
function validateAlphaNumeric(evt, textBox) {
var charCode;
charCode = (evt.which) ? evt.which : window.event.keyCode;
if (charCode >= 97 && charCode <= 122 || charCode >= 65 && charCode <= 90 || charCode == 8 || charCode >= 48 && charCode <= 57 || charCode == 45 || charCode == 13) {
//if (charCode == 13) {
// document.getElementById('SearchButton').click();
//}
return true;
}
else {
return false;
}
}
Can u pls suggest me how to over come this?
Thanks,