Part 2 of a 3 part technical series discussing alternative techniques for coding shared logic and utility methods for use by Quickform and Control event handlers.
Part 1 of this series discussed techniques useful when utilizing the in-line C# Code Snippet Action Item (Obsolete) event handler option.
Part 2 - Technique when using Code Snippet Action item event handlers
If I have one or more form specific helper methods that I’d like to call from several controls event handlers on that form, where do I place the helper methods code since I can only write code for the controls events themselves?
While there is no explicit feature for adding form specific helper methods (hmm – feature request?), it turns out there is a technique staring us right in the face each time we write a code snippet event handler. In fact, thanks actually go to Mark Dykun for pointing out what was staring me right in the face.
Using Application Architect (AA), I generated an Event Handler for the Form OnLoad action event.
AA generates a partial class definition as well as the OnLoad1Step() method.
Notice that AA left the door open for us to sneak as many helper methods as we like just below the OnLoad1Step() method but still inside the partial class definition – thank you AA, we promise to close the door behind us!
OK – so how do I call those helper methods from a control’s Onchange event handler?
The Code Snippet based event handlers for each control on the form will also use the same partial class name and when all codesnippets are compiled together, all form methods – both the event handlers and helper methods will be accesible to each other.
Standards and practices – While this technique will work with any Control event handler method, I recommend always using the Form OnLoad action for this technique so that you and other team members always know where to look for form helper methods.