Tuesday, March 16, 2010

Annoying ASP.NET postback - cursor on top

Scenario
Isn't it annoying that the mouse cursor is positioned to the top of the page for each post back. This happens to components that are not wrapped by a Ajax post-back and with control that has autopostback set to True.

Resolution
For .NET framework 3 and above, set the smartnavigation= true on the aspx Page declaration. Don't worry if the Page tag auto-complete doesn't give you the smartnavigation property.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo.Tricks._Default" smartnavigation="true"%>

Result
If a drop-down box at the bottom of the page is selected and post-back to the server, smartnavigation feature will re-position the cursor to where the post-back occurs. Brilliant!!

No comments: