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 ShaikhRank #839 · 2.7K reputationPosted Oct 31, 2011, 7:41 PM EDT
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 31, 2011, 3:58 PM EDT
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;
}
}
dcRank #2,247 · 627 reputationPosted Oct 31, 2011, 4:43 PM EDT
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 31, 2011, 5:31 PM EDT
dcRank #2,247 · 627 reputationPosted Oct 31, 2011, 7:06 PM EDT
dcRank #2,247 · 627 reputationPosted Oct 31, 2011, 7:53 PM EDT
Can you tell me when these values can be different?
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 1, 2011, 8:26 AM EDT