Asp.net| page
One
private void Retainscrollposition ()
{
StringBuilder savescrollposition = new StringBuilder ();
StringBuilder setscrollposition = new StringBuilder ();
RegisterHiddenField ("__scrollpos", "0");
Savescrollposition.append ("<script language= ' JavaScript ' >");
Savescrollposition.append ("function savescrollposition () {");
Savescrollposition.append ("document.forms[0].__scrollpos.value = Mybody.scrolltop;");
Savescrollposition.append ("}");
Savescrollposition.append ("mybody.onscroll=savescrollposition;");
Savescrollposition.append ("</script>");
RegisterStartupScript ("Savescroll", savescrollposition.tostring ());
if (Page.IsPostBack)
{
Setscrollposition.append ("<script language= ' JavaScript ' >");
Setscrollposition.append ("function setscrollposition () {");
Setscrollposition.append ("mybody.scrolltop =" + request["__scrollpos"] + ";");
Setscrollposition.append ("}");
Setscrollposition.append ("mybody.onload=setscrollposition;");
Setscrollposition.append ("</script>");
RegisterStartupScript ("Setscroll", setscrollposition.tostring ());
}
}
When Page_Load, execute retainscrollposition ()
Page HTML, the body plus id=mybody, you can add this one time, as long as the inherited page will achieve what you want
(quoting others, the original author I forgot, thanks here)
Two
Add an object control to the location you want, let the page refresh and navigate to the position of the control, using the scrollIntoView method.
public void Scrolltoobject (String str_ctl_name,page Page)
{
if (!page. IsStartupScriptRegistered ("Scrollobject"))
{
Page. RegisterStartupScript ("Msgscrollobject", "<script>document.forms" (0). " +str_ctl_name+ ". scrollIntoView ();d ocument.forms (0)." +str_ctl_name+ ". focus (); </script> ");
}
}
Note: Scrolltoobject: Method Name
Str_ctl_name: Control Name