Code of the scroll bar on the page in ASP.net

Source: Internet
Author: User

I found a lot of questions on the internet and found that the answers were messy. In fact, in Asp.net, the page object has a property that enables the page to submit or update data, and then return to the original page location, including the scroll bar location, which can be saved.
Copy the code as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. asp tutorial x. cs" MaintainScrollPositionOnPostback = "true"
Inherits = "Default. Default" %>

Set the MaintainScrollPositionOnPostback attribute to true on the top of the original html page;


How to remove the page scroll bar

When the website was launched today, the customer requested that the website be full screen, using JavaScript:

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<Html>
<Head>
<Script language = "webpage effect">
<! --
Function fullscreen (){
Window. open ("/index.htm", "", "scrollbars = 0, toolbar = 0, location = 0, fullscreen = 1, directories = 0, status = 0, menubar = 0, resizable = 0 ");
}
// -->
</Script>
</Head>
<Body>
<H3 align = "center"> <a href = "j avasscreen: fullscreen ()"> open </a> </Body>
</Html>

However, even if the scrollbars value is 0, the scroll bar will still appear in the full screen. Later I found that to completely cancel the scroll bar, I also need to add:

Overflow: hidden;

Some netizens say that scroll = no can be added to the Body, for example

<Body scroll = no> </body>


The position of the scroll bar after the asp.net tutorial page is refreshed remains unchanged.


Use the MaintainScrollPositionOnPostback attribute

For a very long page, if the IE scroll bar is returned to the beginning (top) after each POSTBACK operation, the original position of the IE scroll bar is not retained, in this way, the user will be more troublesome and move the scroll bar to the original place. In asp.net 2.0, you can set the MaintainScrollPositionOnPostback attribute to TRUE, that is

<% @ Page Language = "VB" AutoEventWireup = "false" MaintainScrollPositionOnPostback = "true" CodeFile = "MaintainScrollPosition. aspx. vb" Inherits = "MaintainScrollPosition" %>

In asp.net, postback is very common. Recently I found a trick to keep the position of the scroll bar after postback.

Very simple. Add an attribute to <% @ Page %>:

SmartNavigation = "true"

In this way, you can maintain the position of the scroll bar in IE, and the page will not flash.

If Firfox is also supported, you can add the following to Page_Load:

Page. MaintainScrollPositionOnPostBack = true;

This attribute is. Net2.0. I used the two methods at the same time. The tests can meet the requirements.

You only need to set MaintainScrollPositionOnPostback = "true" in the Page command of the asp.net Page.

The default value of the MaintainScrollPositionOnPostback attribute is false.

Related Article

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.