Tuesday 10 February, 2009

SmartNavigation Vs MaintainScrollPositionOnPostback in ASP.net 2.0

MaintainScrollPositionOnPostback in ASP.net 2.0

Every one of us know very well about the feature of "SmartNavigation", BUT In Visual studio version 2.0 and above "SmartNavigation" has become obsolete. Now What is the alternate for this, if you want to achieve same feature as "SmartNavigation" then use "MaintainScrollPositionOnPostback".

How to use

Just set Page.MaintainScrollPositionOnPostback = true in page load event and java script will be inserted into your rendered page that maintains the scroll position in the browser window for all post back.
Believe me it's really a good feature in ASP.net 2.0, it would reduce lots of coding effort to maintain scroll position in web page.

Another alternate to maintain page scroll position

This way is same what we do for HTML documents. The following lines you can write into the server side or client side. Below example to write in server side

StringBuilder maintainScrollPosition = new StringBuilder();

maintainScrollPosition.Append("");

Page.ClientScript.RegisterStartupScript(this.GetType(), "Contents", maintainScrollPosition.ToString());

Here entity[0] has a value where you want to set scroll position, in other word it's a flag.You can assume entity[0] is heading in your aspx page and after postback you want scroll position be on this heading.

No comments:

Post a Comment