ASP.NET 2.0 – Validating nonvisible Controls on the same page

asp.netvalidation

I have an application that uses RequiredFieldValidator controls with a ValidationSummary and once a "Finish" button is clicked all the fields are validated. This page has several different parts of it that are made visible or invisible and I noticed that the Validators only activate for visible controls and ignore the invisible ones. This is a useful functionality that is utilized by my program.

however….

I have a need to validate controls that aren't visible since I am splitting up parts of one long page into segments. So I was wondering if there is a way to manually force visible = false validation controls (or ones that are part of an invisible table, etc) to be validated on Page.IsValid, without having to make them visible again?

Thanks in Advance!

P.S. I tried using the ValidationGroup property to see if that would catch them but it didn't.

Best Answer

If the control isn't .Visible then the html isn't there to validate against. Instead of setting Control.Visible = false, try setting a css class to hide it instead.

In your style sheet:

.invisible { visibility:hidden; }

And then instead of .Visible = false use:

Control.CssClass = "invisible";
Related Topic