Što se tiče scroll-persistence, evo koda koji radi posao. Kako kaže, kod samo dodaj u svoju formu i pride jedno this.UseScrollPersistance = true i to je to. A što se fokusa na određenu kontrolu tiče, sigurno mora malčice JavaScript-a da se ubaci - pogledaj po Netu, primera bi trebalo da ima tonu.
Code:
//
// Add this code into your web form (i.e. WebForm1.aspx.cs)
// In your page_Load (or initialization) add this line:
// this.UseScrollPersistance = true;
//
#region Disclaimer
/**********************************************************************
Based on presentation by Brad McCabe of Infragistics
Updated by Scott Watermasysk (http://scottwater.com)
Provided as is, with no warrenty, etc.
Please use however you see fit. Just don't ask for a VB version :)
***********************************************************************/
#endregion
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
#region Scroll Persistence
private bool _useScrollPersistence = true;
/// <summary>
/// There could be PostBack senarios where we do not want to remember the scroll position. Set this property to false
/// if you would like the page to forget the current scroll position
/// </summary>
public bool UseScrollPersistence
{
get {return this._useScrollPersistence;}
set {this._useScrollPersistence = value;}
}
private string _bodyID;
/// <summary>
/// Some pages might already have the ID attribute set for the body tag. Setting this property will not render the ID or change
/// the existing value. It will simply update the javascript written out to the browser.
/// </summary>
public string BodyID
{
get {return this._bodyID;}
set {this._bodyID = value;}
}
//Last chance. Do we want to maintain the current scroll position
protected override void OnPreRender(EventArgs e)
{
if(UseScrollPersistence)
{
RetainScrollPosition();
}
base.OnPreRender (e);
}
protected override void Render(HtmlTextWriter writer)
{
//No need processing the HTML if the user does not want to maintain scroll position or already has
//set the body ID value
if(UseScrollPersistence && BodyID == null)
{
TextWriter tempWriter = new StringWriter();
base.Render(new HtmlTextWriter(tempWriter));
writer.Write(Regex.Replace(tempWriter.ToString(),"<body","<body id=\"thebody\" ",RegexOptions.IgnoreCase));
}
else
{
base.Render(writer);
}
}
private static string saveScrollPosition = "<script language='javascript'>function saveScrollPosition() {{document.forms[0].__SCROLLPOS.value = {0}.scrollTop;}}{0}.onscroll=saveScrollPosition;</script>";
private static string setScrollPosition = "<script language='javascript'>function setScrollPosition() {{{0}.scrollTop =\"{1}\";}}{0}.onload=setScrollPosition;</script>";
//Write out javascript and hidden field
private void RetainScrollPosition()
{
RegisterHiddenField("__SCROLLPOS", "0");
string __bodyID = BodyID == null ? "thebody" : BodyID;
RegisterStartupScript("saveScroll", string.Format(saveScrollPosition,__bodyID));
if(Page.IsPostBack)
{
RegisterStartupScript("setScroll", string.Format(setScrollPosition,__bodyID, Request.Form["__SCROLLPOS"]));
}
}
#endregion
Commercial-Free !!!