Description
The Microsoft.SharePoint.WebControls.SPRememberScroll class inherits from the System.Web.UI.WebControls.Panel class since SPRememberScroll acts as a placeholder for childern controls. However, unlike a Panel control SPRememberScroll is commonly employed for one control rather than grouping related controls. To handle the scrolling position persistence for controls within SharePoint, it is possible to add them to the SPRememberScroll control collection for rendering.
The SPRememberScroll class functions by placing relevant display attributes, namely "ScrollTop" and "ScrollLeft" on the Page object. These can subsequently be called out and through the use of JavaScript functions, maintaining scrolling position when leveraging particular controls.
Usage Scenario
The ordinary usage for the SPRememberScroll control is with navigational elements since they contain user mutable elements, the most common in SharePoint development being the SPTreeView control.
Because of the inheritance of SPRememberScroll from Panel, it can be treated as an orthodox Panel control. When developing a composite control, a new SPRememberScroll object can be hydrated, a control added to the SPRememberScroll.Controls collection, and then added to the current instance control collection for rendering.
In the below, a new SPRememberScroll object is being created and its ID property being set. Following a new SPTreeView object is created, its ID and DataSourceID property set, which is added to the SPRememberScroll.Controls collection. Lastly, the SPRememberScroll object is added to the current instance control collection.
C# Code Example
protected override void CreateChildControls()
{
SPRememberScroll scroll = new SPRememberScroll();
scroll.ID = "Scroller";
SPTreeView view = new SPTreeView();
view.ID = "MyWebTreeView";
view.DataSourceID = "MyDataSourceId";
scroll.Controls.Add(view);
base.CreateChildControls();
}
VB.NET Code Example
Protected Overloads Overrides Sub CreateChildControls()
Dim scroll As New SPRememberScroll()
scroll.ID = "Scroller"
Dim view As New SPTreeView()
view.ID = "MyWebTreeView"
view.DataSourceID = "MyDataSourceId"
scroll.Controls.Add(view)
MyBase.CreateChildControls()
End Sub