I have just been thinking, wouldn't it be good if when a Page Class is defined you could provide some predicates that must be true for the page not to invalid. For instance a developer could provide a list of all the accepted query parameters and their datatypes and the runtime will take car of validating it automatically. I know you can have custom validators and the like but they must always be called via validate.
Wouldn't it be nice if you could do something like:
[QueryParameterValidation(Text)]
protected TextBox inputName;
[QueryParameterValidation(Numeric)]
protected TextBox inputAge;
[QuertParameterValidFields(inputName, inputAge)]
public class TestPage: Page
{
.....
I am not too sure if this type of thing has been done before, or even if it has any advantages over CustomValidaters etc.
I just thought it might be quite handy, because you could seperate the types out so that a Text attribute wouldn't allow HTML/XML characters and it would remove this before the page is completely loaded. So that once the developer sees the data it is HTML safe.
I will have more of a think about this :).
Comments: [Add New]
Ah, could be a nice use of aspect-orientation. I guess it'd be a case of writing a custom attibute class ("QueryParameterValidation"), and testing for it on page initialization, adding validator controls to the control tree as necessary. I found a couple of other ways to do aspects in ASP.NET. You can extend the IExtenderProvider interface (not officially supported in Web Forms but possible via a hack) or create an aspect component that, when dropped on a .aspx page, can affect the behaviour of other controls it is associated with.
, at