views:

434

answers:

1

I'm planning to develop an ASP.NET server control to provide asynchronous username availability validation for new user registrations. The control will allow a developer to point it at a "username" TextBox and it will provide an indication of whether or not the username is available. Like this example, but without the clunky UpdatePanel.

One design decision that's giving me headaches is whether to inherit from ScriptControl or BaseValidator.

By implementing it as a ScriptControl, I can make the client side portion easier to deal with and easily localize it with a resx.

However, I want to make sure that the validator functions properly with respect to Page.IsValid. The only way I know to do this is to override BaseValidator and implement EvaluateIsValid().

So, my question is, how would you suggest structuring this control? Is inheriting from BaseValidator the best (only) way to get the validator part right, or can I do that in some other way?

+2  A: 

You should be able to do both if you implement the IScriptControl interface while also deriving from BaseValidator:

public class YourControl : IScriptControl, BaseValidator

To implement the IScriptControl interface means your control will also have to have the GetScriptReferences and GetScriptDescriptors methods.

Craig
Perfect. Thanks.I started down that road, but tried using override instead of virtual methods for GetScript*, which didn't work. So, I thought it wasn't possible to implement both together.
Dave Ward