hi newsgroup,
i need server side validation of user entries.
as i do have many fields, i would like to use reflection for checkinng
the IsValid property of all the Validators.
here is the reflection code
i don't understand why i get the following error:
Object does not match target type.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Reflecti on.TargetExcept ion: Object does not
match target type.
at this line: object
ret=field.Field Type.GetPropert y("IsValid",typ eof(bool)).GetV alue(field,null );
the code is a loop the goes through all public fields of the user control:
public static bool checkValidators (Control page)
{
bool isValid=true;
FieldInfo[] fields=page.Get Type().GetField s();
foreach(FieldIn fo field in fields)
{
if(field.FieldT ype.IsSubclassO f(typeof(System .Web.UI.WebCont rols.BaseValida tor)))
{
object
ret=field.Field Type.GetPropert y("IsValid",typ eof(bool)).GetV alue(field,null );
isValid=Convert .ToBoolean(ret) ;
}
}
return isValid;
}
any ideas?
or maye there is another way to check the IsValid property of all the
validators in a fast way?
thanks for your help.
dan