Who has not used the window.confirm() method to display a
confirmation dialog box to the user before continuing the processing on the
server side? I actually loved that dialog box when I first started using it;
however, two annoying things were pushing me to create my own custom dialog.
·
Default button focus: The default selected button is
"OK." Consider that you have a grid control and a delete button on
its rows to allow the user to delete a certain row and on the delete button
click event you would like to show a confirmation message. It is good practice
to show such a dialog box in such operations. However, if the user clicks by
mistake the enter keyboard key, the OK button click event is handled.
·
Default Buttons: The two default buttons are OK and Cancel and
they cannot be modified.
The benefits for using this custom dialog box are as follows:
·
The need to set a default button to a different control other
than the OK button.
·
The need to change the text for the buttons to a value different
than the default ones used by the web browser (in this example I have used Yes
and No), and finally, the need to change its appearance.
One last thing I should mention is the ability of this
dialog box to re-locate itself once the window is resized. In this way the
dialog box will always appear in the center of the window.