views:

30

answers:

1

I'm trying to place a user control inside an UpdatePanel. When the control is displayed, typing inside the TextBoxes has a large delay while in IE (6 & 8). FireFow has an excellent performance. Not only typing, but also scrolling etc experience a large delay up to a few secons.

The usercontrol(s) contain quite a lot of javascript functions that are re-registered using the ScriptManager.RegisterScriptBlock or RegisterStartupScript functions.

Has anyone any ideas why typing becomes so very slow? I believe it has to do something with memory leaking due to the re-registering of the jQuery functions. But I'm unable to find the source of it.

Regards

A: 

JavaScript written by yourself or others or part of a reliable framework?

Generic tips: - reduce processes and function calls - delegate events - cache and reuse jQuery results (especially for IE) and only requery when you know the DOM changed. - avoid recursion unless you know how to avoid all memory leak prone practises. - Concerning form inputs, use 'focus' and 'blur' events rather then 'keypress' wherever you can. - When using 'keypress' events, debounce, debounce, debounce! (google it)

Use: - Firebug profiler to see which functions are called and how many times, this shows you what you need to reduce.

BGerrissen
Thanks for the sugestions. We're actually having all kind of javascript, my own, written by collegues and embedded in custom controls written by our framework team. I'll have a look at the delegate events and the caching (for everything outside the updatepanel).
Littlefool
Your suggestion for using Firebug profiler helped a lot. I didn't knew about this feature. We found code that looked like $('body').keypress(function(){});. This caused about 50 calls every time we typed something. Thanks again for the good advice.
Littlefool
$(body).keypress(..) is imo. an anti pattern for event delegation since it's a catch-all-always-firing listener. Bind listeners to the closest possible ancestor (ie. the form element to catch events inside a form, or the ul element to catch events of list items). Also, consider lazy-attaching event listeners to when they are needed rather then always onDomReady.
BGerrissen