[Summary]
It involves the DTD template standard, which is annoying and has to be determined, Only passed the test in IE browser.
This is where vs2008 pages all have this, and will affect the style and script:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
You can call the restorescroll method directly in page_load. For details, see Code Note.
[Code] Using System;
Using System. Data;
Using System. configuration;
Using System. LINQ;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. htmlcontrols;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. xml. LINQ;
/**/ /// <Summary>
///Summary of ax
/// </Summary>
Public Class Ax
{
Public Ax ()
{
}
Public Static Void Restorescroll (page)
{
// Register a hidden filed
Page. clientscript. registerhiddenfield ( " Hidden_ax " , " 0 " );
System. Text. stringbuilder sb = New System. Text. stringbuilder ();
// When the scroll bar is rolled, it is saved to the top position of the page in the hidden field.
SB. appendline ( " Function getpagescroll () " );
SB. appendline ( " { " );
SB. appendline ( " VaR yscroll; " );
SB. appendline ( " If (document.doc umentelement. scrolltop) // page compliant with the DTD Standard " );
SB. appendline ( " { " );
SB. appendline ( " Yscroll = document.doc umentelement. scrolltop; " );
SB. appendline ( " } " );
SB. appendline ( " Else " );
SB. appendline ( " { " );
SB. appendline ( " Yscroll = Document. Body. scrolltop; " );
SB. appendline ( " } " );
SB. appendline ( " Return yscroll; " );
SB. appendline ( " } " );
SB. appendline ( " Function savescrollposition () " );
SB. appendline ( " { " );
SB. appendline ( " Document. getelementbyid ('den den _ ax '). value = getpagescroll (); " );
SB. appendline ( " } " );
SB. appendline ( " Window. onscroll = savescrollposition; " );
Page. clientscript. registerstartupscript (page. GetType (), " Ax " , SB. tostring (), True );
// Restore the position of the scroll bar after the page is loaded.
If (Page. ispostback)
{
SB. Remove ( 0 , SB. Length );
SB. appendline ( " Function setscrollposition () " );
SB. appendline ( " { " );
SB. appendline ( " Window. scrollto (0, " + Page. request [ " Hidden_ax " ] + " ); " );
SB. appendline ( " } " );
SB. appendline ( " Document. Body. onload = setscrollposition; " );
Page. clientscript. registerstartupscript (page. GetType (), " Axzhz " , SB. tostring (), True );
}
}
}
Call Public Partial Class _ Default: system. Web. UI. Page
{< br> protected void page_load ( Object sender, eventargs E)
{< br> ax. restorescroll (PAGE);
}
}