Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET button click event still firing even through custom server-side validation fails

I am having a problem where my button click event is still firing even though my custom server-side validation is set to args.IsValid = false. I am debugging through the code and the validation is definitely being fired before the button click, and args.IsValid is definitely being set to false once the custom validation takes place, but it always makes its way to the button click event afterwards. Any ideas on why this is?

like image 373
Josh Avatar asked May 27 '10 18:05

Josh


1 Answers

Not sure 100% of the particulars, but to prevent code from continuing, add to your button click event handler:

if (!Page.IsValid)
     return;

That will prevent the code from executing.

like image 71
Brian Mains Avatar answered Oct 09 '22 10:10

Brian Mains