开发者

ASP.NET Validator Controls Slowing Down Page

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.

Thanks,

开发者_如何学PythonCalvin


If you have a lot of those validators, and client-side validation is enabled, the browser could be having a tough time grinding through all of them.


There are couple of things. First all the ASP.NET Validation controls generate massive amount of JavaScript which is added to the page as WebResource or ScriptResource. Those scripts are downloaded once and then cached so they should not cause the problems for causing slowness on frequent basis.

The other thing is update panel. The update panel is an awesome control but it does relay on ViewState. Which means whatever control you put inside the update panel the view state for that control will be sent to the server on postback. As controls inside the UpdatePanel increases the ViewState will increase.

One solution might be to turn off ViewState on controls that don't need them. You can also force the ViewState to move at the bottom of the page. This will make sure that the ViewState is downloaded at the end.

Here is my post which describe how to create ViewState mover control:

http://azamsharp.com/Posts/139_ViewStateMoverModule_Released_.aspx


Most of (all of?) the ASP.NET validation controls have been around since the first version of the .NET framework, and they conform to the general web controls vibe of that era: 'works fine on my T1 line.'

For performance-sensitive applications, I just wouldn't use these. There are workarounds, but the cure may be worse than the disease. (For example, you might do all the validation on the server by setting EnableClientScript = false.)

Nowadays, I generally use the jQuery Validation plugin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜