Simplify ASP.NET AJAX client-side initialization
AJAX, ASP.NET, UI By Dave Ward. Updated March 24, 2009I recently found myself needing to perform a bit of client-side page initialization, both on initial page load and when partial postbacks completed. I muddled through by using window.OnLoad() for the initial page load and an EndRequest handler for partial postbacks. It worked, but I wasn’t very happy with the kludgey nature of it.
On an unrelated ASP.NET forums thread around the same time, Steve Marx pointed out to me that the AJAX framework automatically wires up any client-side function named pageLoad() as an Application.Load handler. It’s actually in the docs, if you dig for it:
To handle the load and unload events of the Application object, you do not have to explicitly bind a handler to the event. Instead, you can create functions that use the reserved names pageLoad and pageUnload.



When you have a name as common as mine, you run across the entire gamut of schemes to deal with username availability in membership systems. By availability, of course I mean denial and rejection. Out of all of the ways that I’ve had “Dave” rejected, inline AJAX verification is definitely the least annoying. Wanting to be less-annoying myself, I’ve added the same functionality to my ASP.NET AJAX sites. Let me show you how I did it.
