I am using javascript for required field validation,i have used alert box,after clicking ok in alert box then also controls goes to server side code for save click
function IsFieldEmpty() {
var txtAgent_Name = document.getElementById("<%=txtAgent_Name.ClientID %>");
if (txtAgent_Name.value == "") {
alert('Please Enter Agent Name');
txtAgent_Name.focus();
return false;
}
}
If the problem is that some event handler is still submitting data after showing an
alertinforming of a validation error, you’ll probably need to make the event handler function returnfalseafter showing thealert, in order to prevent further processing of the event.As pointed out by @Bergi in his comment, and if you’re using JQuery or another framework, you might need to use
stopPropagation()or equivalent. SeeUPDATE
Seeing the code posted, it might be important to remark that the
return falseis being done inside theIsFieldEmptyfunction. That means thatfalseis the return value forIsFieldEmpty. Take into account that if you’re submitting data in a similar way to this:IsFieldEmptywill return false but the event handler won’t. If it’s the case, you should change it to:and make
IsFieldEmptyreturntruewhen validations are passed.