You're making work for yourself.
The built-in validator controls run both client-side and server-side. Since they emit JavaScript to run client-side, and it's really easy to simply disable JavaScript in any modern browser, the developers at Microsoft had the foresight to protect against how easily validation could be by-passed by having the controls operate server-side as well. I believe (and you can double-check this if you'd like), all you have to do is check the Page.IsValid property to find out if any of the validation controls failed validation on Postback (this happens server-side). You can then access the Page.Validators collection to find out which validator failed (there may be an easier way to do this -- Google it).
If you don't want to use the standard validators, then I wouldn't bother creating a control when a simple method / property will do the trick. I'd probably add a property to your page such as the following:
Code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsValidCustom)
{
// DO STUFF HERE
}
}
private readonly bool IsValidCustom
{
get
{
return string.IsNullOrEmpty(TextBox1.Text.Trim());
}
}
}
If you need to check more controls, then simply add the checks to the IsValidCustom property. If you need custom error messages (perhaps written to a label control), then you need to write your own validation subroutine / function (depends on whether you want some kind of return value or not).