DNN-4756: Performance issue loading edit mode with 50+ modules on page

added code from Je on the forums and updated it slightly for line termination errors.