Sunday, June 29, 2008

ASP:Button's UseSubmitBehavior

There's a really cool way to extend an ASP.NET button's functionality in JavaScript and that's by getting ASP.NET to render the button as an Input Button control instead of an Input Submit control - this is done by setting the UseSubmitBehavior property to False.

You can call GetPostBackEventReference to get the Javascript to call the onClick event handler for the button if you need it - this is appended to the OnClientClick handler automatically.

A practical usage scenario is when you want to use a custom dialog with a ModalPopupExtender to confirm a certain action... with a regular confirm dialog, you can return a true or false within the OnClientClick but you can't do that with a custom dialog.

No comments: