Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override ScriptControl or BaseValidator for an async ASP.NET validator control?

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?

like image 663
Dave Ward Avatar asked Oct 15 '22 19:10

Dave Ward


1 Answers

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.

like image 171
Craig Avatar answered Nov 03 '22 01:11

Craig