Best Practices on ASP.NET AJAX Bill Xie Jan 30, CSU Fullerton SoCal Code Camp
ASP.NET AJAX ASP.NET Web Forms Addon Not a Pure AJAX Framework -- Partial Rendering, ScriptManager, UpdatePanel Great Backward Compatibility with ASP.NET Web Forms -- apply all skills in Web Forms to AJAX application
ASP.NET AJAX Declarative syntax Async triggers can be any controls Support custom events Web service integration Page methods Client library A big set of ASP.NET AJAX server controls
Where Are The Problems Declarative syntax does not work in all cases -- UpdatePanel nested in a Repeater Lack a full picture of how UpdatePanels and Async Triggers are associated. -- Too many SEPARATE event handlers Use of complex controls as async triggers and custom events -- Repeater, GridView, User Controls, etc -- Distorting the meaning of async triggers -- Make code hard to read
What Are The Problems Contd Page As One Application -- Imagine more and more more and more async triggers and UpdatePanels BIG PROBLEM -- Change and Maintenance Better way to do the ASP.NET AJAX instead of the ad hoc way? -- Consistent, simple, straightforward, ….
Can We Solve The Problems? Fortunately, the answer is YES A reduced set of ASP.NET AJAX can do the trick The solution still keeps the pros of all ASP.NET AJAX good features, but it leads to applications much easier to change and maintenance
The Solution Decouple async triggers and UpdatePanels at design time -- Specify async triggers (inside UpdatePanel, page-level trigger with instance, nested) -- Wrap areas wherever you want to update in the async postback with UpdatePanel Centralized handling of async postbacks -- Identify async triggers with AsynchronousPostBackElementID -- no event handlers, if else or switch instead -- Associate UpdatePanels dynamically (ChildrenAsTriggers) Some tweaks -- GridView sorting event Demo
Case Studies Async Triggers Page looks simple but databinding is very complex
Case Studies UpdatePanels
Q & A You can find the technique in this article magazine.com/Article.aspx?quickid= Search bill xie Contact me --