Rank: Administration
Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor Joined: 23/11/2008(UTC) Posts: 520
|
1. In your markup file (.aspx), add the Java script: Code:var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(beginRequest);
prm.add_endRequest(endRequest);
function beginRequest()
{
prm._scrollPosition = null;
}
function endRequest()
{
}
2. add the following two generic methods in the class file(where utilities exist) if the control is a postback control Code: public static void ScrollIntoView(Control controlToScroll)
{
Page page = HttpContext.Current.Handler as Page;
//please note that the "script" and "/script" should be the open and close tags
page.RegisterStartupScript("key1", "script document.getElementById('" + controlToScroll.ClientID + "').scrollIntoView();/script");
}
if the control is an asyncronous postback control Code: public static void ScrollIntoViewForAsync(Control controlToScroll)
{
Page page = HttpContext.Current.Handler as Page;
//ScriptManager.RegisterClientScriptBlock(page, typeof(page), "key2", "document.getElementById('" + controlToScroll.ClientID + "').scrollIntoView();", true);
ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "key2", "document.getElementById('" + controlToScroll.ClientID + "').scrollIntoView();", true);
}
|