So I have made a custom required field validator that turns the background of a textbox red. For this I have implemented a custom control that inherits from required field validator.
Everything is working great and the control functions properly. The only thing is that the control does a post back and the error of the custom required field validator is not caught in the validation section of the page life cycle.
public class MVADRequiredFieldValidator : RequiredFieldValidator
{
protected override void OnInit(EventArgs e)
{
if(Page.IsPostBack)
{
Validate();
var mvadRequiredFieldValidator = this;
var controlToValidate = ControlToValidate;
TextBox tbToChange = (TextBox)FindControl(controlToValidate);
if(!IsValid)
{
if (tbToChange != null)
{
tbToChange.CssClass = "error";
}
}
else
{
if (tbToChange != null)
{
tbToChange.CssClass = "nonError";
}
}
}
//OnInit(e);
}
}
I know about the asp.net page life-cycle but I have not yet found a method to override that will register the error with the collection of errors on the page.
Thanks
What about EvaluateIsValid(); Seems to be what you want
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.evaluateisvalid.aspx
from this post
http://forums.asp.net/t/1049481.aspx/1
This seems really similar to waht you want to do
http://www.codeproject.com/KB/aspnet/enhacedvalidator.aspx