Canceling AutoPostBack for Asp.Net DropDownList
January 25, 2010
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.
Reference: http://forums.asp.net/p/1475520/3432980.aspx
–Adam
Leave a Reply