Alternative implementation of smartnavigation in Asp.net web smart navigation

Source: Internet
Author: User

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 ());

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.