Preventing Pages with Invalid Content from Being Saved
There’s still a problem to be tackled. Although the custom validation control has all the necessary code, it won’t work unless someone clicks on an ASP.NET control, such as a Button, that has its Control.CausesValidation
property set to true. Otherwise, the page will still be saved even if required placeholders are not filled in.
If you looked at the way the controls on the Default Console are coded (in the Defaultconsole.ascx
file), you will find that they are simply HTML anchor tags. HTML anchor tags are not buttons and therefore do not trigger page validations. As a result, clicking on any of the action links on the console will not fire our custom validation control.
We need the validator to fire when the user clicks one of the following three action buttons:
Save New Page
Save
Save and Exit
We will modify the behavior of each of the three buttons to cancel the save action when the page is not valid...