Canceling AutoPostBack for Asp.Net DropDownList

In my most recent project, I decided to prompt the user before doing a post back when a DropDownList changed. In order to do so, you need to add an “onchange” event to your DropDownList. It should look something like:

onclick="if(!SomeFunction(this)) return false;"

Some Notes:

  • “SomeFunction” is a javascript function that returns true or false based on your criteria.
  • On first inspection, I thougth that I could just call the funciton without wrapping it in what apppears to be a useless IF statement. However, for whatever reason, this IF statement is necessary to cancel the automatic postback.