Http://czm600604604.blog.163.com/blog/static/825206820094215237512/
Alternative implementation of smartnavigation in Asp.net web smart navigation
During the development of Asp.net projects, intelligent page navigation is often encountered. The smartnagivation provided by Asp.net was initially used, but because smartnavigation is implemented by embedding IFRAME In the webpage, problems often occur. For example, the use of frame pages may cause invalid style pages and problems with the verification control. Many materials have been collected from the Internet, most of which are implemented by saving the current view location of the webpage through javascript. Page jitter often occurs when used.
I occasionally found a solution in Microsoft's example,CodeAs follows:
Private sub retainscrollposition ()
Dim savescrollposition as new stringbuilder ()
Dim setscrollposition as new stringbuilder ()
Registerhiddenfield ("_ scrollpos", "0 ")
Savescrollposition. append ("<script language = 'javascript '> ")
Savescrollposition. append ("function savescrollposition (){")
Savescrollposition. append ("document. Forms [0]. _ scrollpos. value = thebody. scrolltop ;")
Savescrollposition. append ("}")
Savescrollposition. append ("thebody. onscroll = savescrollposition ;")
Savescrollposition. append ("</SCRIPT> ")
Registerstartupscript ("savescroll", savescrollposition. tostring ())
If (page. ispostback = true) then
Setscrollposition. append ("<script language = 'javascript '> ")
Setscrollposition. append ("function setscrollposition (){")
Setscrollposition. append ("thebody. scrolltop =" & request ("_ scrollpos ")&";")
Setscrollposition. append ("}")
Setscrollposition. append ("thebody. onload = setscrollposition ;")
Setscrollposition. append ("</SCRIPT> ")
Registerstartupscript ("setscroll", setscrollposition. tostring ())
End if
End sub
Call this function in page_load. In addition, name the body Id thebody on the aspx page.
In general, viewstate is used to save the current location, but it is easy to use.
Posted onDoudouReading (810)Comment (2)Edit Favorites Network AbstractCategory:Dribs and drabs
# 1st Floor ReplyReference# Floor 2 Doudou
It's okay to use C #. This is my method.
/// <Summary>
/// Page smart navigation function
/// Ensure the body. ID = thebody;
/// </Summary>
/// <Remarks> when using this function, you must add the tree id = "thebody" to the body; otherwise, JavaScript errors may occur. </Remarks>
Protected void retainscrollposition ()
{
Stringbuilder savescrollposition = new stringbuilder ();
Stringbuilder setscrollposition = new stringbuilder ();
This. registerhiddenfield ("_ scrollpos", "0 ");
Savescrollposition. append ("<script language = 'javascript '> ");
Savescrollposition. append ("function savescrollposition (){");
Savescrollposition. append ("document. Forms [0]. _ scrollpos. value = thebody. scrolltop ;");
Savescrollposition. append ("}");
Savescrollposition. append ("thebody. onscroll = savescrollposition ;");
Savescrollposition. append ("</SCRIPT> ");
Registerstartupscript ("savescroll", savescrollposition. tostring ());
If (page. ispostback)
{
Setscrollposition. append ("<script language = 'javascript '> ");
Setscrollposition. append ("function setscrollposition (){");
Setscrollposition. append ("thebody. scrolltop =" + request ["_ scrollpos"] + ";");
Setscrollposition. append ("}");
Setscrollposition. append ("thebody. onload = setscrollposition ;");
Setscrollposition. append ("</SCRIPT> ");
Registerstartupscript ("setscroll", setscrollposition. tostring ());
}
}