The OnValidate event fires for each field in your main DOM before the OnLoad event is fired. This allows you to write validation code to add custom errors to the Errors collection for invalid fields before the user ever sees the view. This might be necessary when you are unsure of the source of the XML and for numerous other reasons. Although very useful, you might have validation event handlers that you do not want processed at this point. It is possible to prevent these validation event handlers from being processed.
Because the View object does not exist until the first OnSwitchView event, which occurs after the OnLoad event, you can use this to detect whether your validation event handler is being called before the OnLoad event. To skip this initial OnValidate event, add the following code to the beginning of your validation event handler:
if(null == eventObj.XDocument.View) return; // Ignore OnValidate before the OnLoad event. |
©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.