C# – Run a Javascript function before postback

asp.netcnet

On my ASPX page, there is a button with this code:

OnClick="save_Click"

Is it possible to execute Javascript before postback and if the result is true, then do the postback and go to method save_click?

Best Answer

There is a property called "OnClientClick" as well. Here you can specify a function that will validate (I'm guessing), or just run regular javascript.

If your data is not valid you can just return false; from the method. That should cancel your postback