You are probably doing postback by pressing "enter", the tab does not postback.
Regarding the validation by change of focus, this is done with Jquery. What you should do is:
1-Assign Id to Textboxes. Let's say id = texbox1, id = texbox2
2-Add Jquery library to your page. This can be done by calling the online or offline bookstore.
A-Para llamarla de forma online tendrias que poner algo asi en la cabecera de tu header: <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
B-Si la quisieras tener offline la tendrias que descargar en una carpeta de tu proyecto y llamarla.<br/>
3-Create a section < script > on your html page
4-Inside the script section create a JQuery section in the following way:
jQuery (function ($) {
All the code goes here in the middle
});
5-Inside the Jquery section are called the events "onChange" of textbox1 and textbox2 as follows:
$("#TextBox1").on('change', function () {
Validar();
});
$("#TextBox2").on('change', function () {
Validar();
});
6-Then we created the validate function, which could validate the quality of the information entered or the existence of a data in the database. If it were the latter you should create an Ajax function as follows:
function Validar(Valor){
$.ajax({
url: '/NombreDeTuPagina/NombreDelActionResult',
data: { variableActionResult: Valor },
dataType: 'json',
type: 'GET',
success: function (result) {
return result;
},
error: function (data) {
}
});
}
-url is the php or controller page you use / The name of your actionresult or method
-data are the variables that the action result or method receives
-Value is the variable that you pass
-dataType here you clarify that it is json
-type you have GET and POST, in this case we use GET to receive a value and not do postback
-success is what happens when the action result is executed without errors
-result is the variable that the action result should return (remember to return a value in action result)
-In this case I return it to whoever calls it, X number of things could be done, put if, for, etc, etc, assign a sign to a div.
7-The events On change of point 5 should be modified to be according to point 6, I put them with little code so you do not get lost, but I update them below:
$("#TextBox1").on('change', function () {
var variable =$("#TextBox1").val(); //aca capturo el valor del txtbox
if(Validar(variable )==true){ //Validar deberia devolver un bool para que funcione
... todo ok
}else{
...en caso de no validar podria tirar un warning o dejar un mensaje en un div debajo del textbox
}
$("#TextBox2").on('change', function () {
var variable =$("#TextBox2").val();//aca capturo el valor del txtbox
if(Validar(variable )==true){ //Validar deberia devolver un bool para que funcione
... todo ok
}else{
...en caso de no validar podria tirar un warning o dejar un mensaje en un div debajo del textbox
}
});
Beyond everything explained, I recommend using HTML5 validations, they are easier and they are automatic, you only have to declare if X field is numeric, or text, or date, or if you have X pattern and you are ready, and Automatically validates when you submit by generating the posters automatically.
I hope you have been useful !!!