I have an UpdatePanel that has user controls dynamically added to it. There can be a few dozen user controls at times.
The page / UpdatePanel slows down big time on each postback as more user controls are added. After some digging, I was surprised to find the cause is the various CompareValidator, CustomValidator, RegularExpressionValidator and RequiredFieldValidator controls that exist on each user control.
Does anyone have suggestions? It strikes me as very peculiar that inclusion of these ASP.NET controls could have such a horrible effect on performance.
I’m just looking at the time required to render the user controls. For about two dozen controls, it takes the UpdatePanel roughly 10 seconds to “refresh” after a postback is initiated by a button click.
I determined it was the validation controls by removing them from the user control class. Once that was done, the response time was about two seconds for the same number of user controls.
The problem is probably the viewstate of the page that is so big after you added all the controls. And that large viewstate is causing the page to slow down. You could try compressing it(google it). You could disable it, but seing as tho its a form, I would assume viewstate is required?
By looking at the HTML, I can confirm that massive amounts of Javascript are generated directly for:
the array containing the page validators
assignment of properties (e.g., “errormessage”, “validationGroup”, “evaluationfunction”, etc.) to the validators
creation and assignment of “dispose” logic
For a couple dozen user controls, the validator code that’s generated is roughly 1600 lengthy lines, more than half of the total page size. The volume of this code going over the wire, in addition to the time required to process it once it reaches the client, is the problem.
Because this code is auto-generated by ASP.NET, I am guessing there is not much I can do. Can anyone confirm or deny this?
That sounds right presuming you have enough stuff. You could disable the client-side validation option, which would keep the script off the wire. End of the day, you really need to rethink that user interface to keep stuff palatable, or decide that big loads of data are palatable.
The problem is the js that is going over the wire. Only thing that can help is HttpCompression.
I would suggest that you disable client side validation, and maybe go for a jQuery js option that lives on the page that handles client side validation.
Yup, and due to the component based nature of ASP.NET webforms, it can’t figure out that “oh, smack, there are 11 user controls just like me. Let’s cache the JS bits on a separate resource.”
Best bet is to rethink the interface so you don’t have as much active at once. Perhaps making the UpdatePanel a bit more targeted could help–it won’t save on ViewState, but it should keep the js passing a bit more under control if it isn’t sending the entire list of controls. Other trick is you are probably figuring out that ASP.NET AJAX is synchronous (basically due to ASP.NET limitations), so you don’t really have too many options ui-wise.