One of the things I hate about the joy of postbacks is losing my scroll position. On a page that's a bit longer than the window, if I have an auto-postback combobox (for example), the user selects an item, the page posts back, and poof! they're back at the top of the page.
On a corporate intranet the post back is nice and fast, and many times the user has no clue that it happened.... Except for the fact that the page just "jumped" back to the top.
Because of this I (as many people) write my controls to re-position, or I have page logic to re-position after a postback. There are articles on CodeProject with controls for keeping the scroll position, one on DotNetJunkies that isn't quite so pre-packaged, but still good, and several tutorials. The problem then is that the behavior is coded in everywhere, or the control must be included on each page, or the page must be derived from something other than the Page class, or something else.. I wanted a fire and forget solution.
So here's what I created late last night to un-vex myself -- an HTTPModule that adds scroll position retention across postbacks to all pages. It's implemented as a filter that adds javascript to the pages after they are output. I've tested it only on IE 6, as that's the browser my client site's intranet uses.
The nice thing about this (to me) is that three lines in your web.config instantly gives you scroll position retention across postbacks on every page in your application. No muss, and not a whole lot of fuss.
To use it, add the module in to your web.config (see the readme.txt included for instructions on doing this), and then configure it to either add the behavior to all pages, or be selective (again, see the readme.txt). The zip includes the source, and a pre-build binary that's strongly named in case you want to just drop it in.
If you find any bugs or problems with it, fix 'em yourself! No, really you can just leave me a comment here and I may look at it. The module works great for me (the infamous "it works on my machine!" that translates to "it only works on my machine!"), and hopefully will for you too. If you like the code, I wrote it. If you don't like the code, then some other idiot wrote it.
[Update - 3/20/04] A Francois Massey contacted me with an interaction problem, most likely due to the fact that all output is buffered by the ScrollKeeper module. Unfortunately, ScrollKeeper would buffer output even if you had configured it to ignore pages... that is, it would buffer all output just by being defined in the web.config as a module. Oops! The links to download now point to an updated version that takes no action on ignored pages. Thanks for pointing out the problem, Francois!
[Update - 10/17/04] The module was not applying the onload to empty body tags correctly, and was not using UTF8 encoding consistently. While these were fixed a while ago, I didn't have the download links correct! Now with my new-fangled Cruise Control.Net process, these should be auto-updated when I make fixes.
ScrollKeeper - Full Source
ScrollKeeper - Binaries only