Performance Programming with ASP.NET Ajax
At first glance, ajax seems to be a cinch with asp.net 3.5, what with all the updatepanel, timers and such. However behind this ease of development hides a danger which most developers may not notice.
Although updatepanels and timers are easy to use, each update triggers a complete postback and if your viewstate is on the page, its an extremely large form post. On the server side, each event of a normal postback is called, and the whole control tree is generated to handle the ajax form post. This is quite intensive both for the server and for the client.
Nexus initially went with the first approach (i.e a whole bunch of updatepanels), but the results were less than impressive. Moving onto the second approach required a revamp of the whole source code, but this gave the user a much better experience along with substantially reducing server load.
To reduce the footprint on the server side, i utilized ScriptManager’s ServiceReference parameters
<asp:ScriptManager ID="ScriptManager" runat="server" onasyncpostbackerror="ScriptManager_AsyncPostBackError"> <Services> <asp:ServiceReference InlineScript="true" Path="JSON.asmx" /> <asp:ServiceReference InlineScript="true" Path="ProxyAsync.asmx" /> </Services> </asp:ScriptManager>
[WebMethod] [ScriptMethod(UseHttpGet = false, XmlSerializeString = true)] public JSON_Tabs UserFirstLoad()
As i’m not using UpdatePanel, GUI updates are done directly via DOM. Fortunately Ajax ClientScripts provide some global functions which i can use to
- Locate the element i want to update ($get)
- Add events to the element ($addHandler)