I am trying to change the css of a textbox based on an error on the page. Say to turn the background of the textbox red. I want to do this through the base page so that each codebehind that inherits this base page will perform this function. I am trying to do this in the OnLoad event
protected override void OnLoad(EventArgs e)
{
//code here
base.OnLoad(e);
}
How do I access the error collection in the base page something like this…
for each(var error in Page.Errors)
{
TextBox textBox = error.textboxInError;
textBox.Background - Color = "Red";
}
To be more specific I want to trigger on page validation errors.
If you’re using web forms validators, you could do something like this:
Update
Apparently, the
Pageobject has a collection of validators. See Page.Validators. Here’s some revised code using that: