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.Reflection.TargetException: Object does not
match target type.
at this line: object
ret=field.FieldType.GetProperty("IsValid",typeof(b ool)).GetValue(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.GetType().GetFields();
foreach(FieldInfo field in fields)
{
if(field.FieldType.IsSubclassOf(typeof(System.Web. UI.WebControls.BaseValidator)))
{
object
ret=field.FieldType.GetProperty("IsValid",typeof(b ool)).GetValue(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