I am working on some new C# asp.net 2010 webforms. I am using the validator controls to make certain the user enters required data accurately. I have heard that we should be using args.IsValid in the controls. However, I do not know how to 'write this up'. Can you point me to examples of how I can make my four controls use args.IsValid? I also would like an example of what I check when this value is false.
Loading
Javeed M ShaikhPosted Oct 31, 2011, 11:41 PM
Javeed M ShaikhPosted Nov 1, 2011, 12:26 PM
dcPosted Oct 31, 2011, 11:53 PM
Can you tell me when these values can be different?
dcPosted Oct 31, 2011, 11:06 PM
Javeed M ShaikhPosted Oct 31, 2011, 9:31 PM
dcPosted Oct 31, 2011, 8:43 PM
Javeed M ShaikhPosted Oct 31, 2011, 7:58 PM
The args.isvalid is used to get or set the value specified if the validation is passed or failed. here is an example:
ErrorMessage="My Error Message"
OnServerValidate="MyValidationFunc"
runat="server"/>
and than in code behind:
void MyValidationFunc(object source, ServerValidateEventArgs args)
{
try
{
// do your validation here and if all ok set to true otherwise false.
//if all ok
args.IsValid = true;
//otherwise
// args.IsValid = false;
}
catch(Exception ex)
{
args.IsValid = false;
}
}