using
System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Document
{
/**//// <summary>
/// Summary description for WebForm5.
/// </summary>
public class WebForm5 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox pos;
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
}
protected string writebutton()
{
string script="";
script="<table>";
for(int m=0;m<100;m++)
{
script+="<tr><td>";
script+=m;
script+="</td></tr>";
}
script+="</table>";
return script;
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Document
{
/**//// <summary>
/// Summary description for WebForm5.
/// </summary>
public class WebForm5 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox pos;
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
}
protected string writebutton()
{
string script="";
script="<table>";
for(int m=0;m<100;m++)
{
script+="<tr><td>";
script+=m;
script+="</td></tr>";
}
script+="</table>";
return script;
}
}
}
1.窗体自身滚动条定位控制
<
HTML
>
< HEAD >
< title > 窗体自身滚动条定位控制 </ title >
< meta content ="Microsoft Visual Studio .NET 7.1" name ="GENERATOR" >
< meta content ="C#" name ="CODE_LANGUAGE" >
< meta content ="JavaScript" name ="vs_defaultClientScript" >
< meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema" >
< SCRIPT type ="text/javascript" > <!--
function onscrollform()
{
document.all["pos"].value = document.body.scrollTop;
}
function formOnload()
{
OnloadForScroll();
}
function OnloadForScroll()
{
var spos = document.all["pos"].value;
window.scrollTo( 0, spos );
}
--> </ SCRIPT >
</ HEAD >
< BODY onscroll ="onscrollform();" onload ="formOnload();" scroll ="yes" ms_positioning ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
<% = writebutton() %>
< asp:textbox id ="pos" style ="DISPLAY: none" Runat ="server" ></ asp:textbox >
< asp:Button id ="Button2" style ="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 520px" runat ="server"
Text ="可以将页面缩小,把滚动条往下拉看效果" ></ asp:Button >
</ form >
</ FORM >
</ BODY >
</ HTML >
< HEAD >
< title > 窗体自身滚动条定位控制 </ title >
< meta content ="Microsoft Visual Studio .NET 7.1" name ="GENERATOR" >
< meta content ="C#" name ="CODE_LANGUAGE" >
< meta content ="JavaScript" name ="vs_defaultClientScript" >
< meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema" >
< SCRIPT type ="text/javascript" > <!--
function onscrollform()
{
document.all["pos"].value = document.body.scrollTop;
}
function formOnload()
{
OnloadForScroll();
}
function OnloadForScroll()
{
var spos = document.all["pos"].value;
window.scrollTo( 0, spos );
}
--> </ SCRIPT >
</ HEAD >
< BODY onscroll ="onscrollform();" onload ="formOnload();" scroll ="yes" ms_positioning ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
<% = writebutton() %>
< asp:textbox id ="pos" style ="DISPLAY: none" Runat ="server" ></ asp:textbox >
< asp:Button id ="Button2" style ="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 520px" runat ="server"
Text ="可以将页面缩小,把滚动条往下拉看效果" ></ asp:Button >
</ form >
</ FORM >
</ BODY >
</ HTML >
2.窗体自身滚动条被禁止,而通过div的滚动条来定位控制
<
HTML
>
< HEAD >
< title > 窗体自身滚动条被禁止,而通过div的滚动条来定位控制 </ title >
< meta content ="Microsoft Visual Studio .NET 7.1" name ="GENERATOR" >
< meta content ="C#" name ="CODE_LANGUAGE" >
< meta content ="JavaScript" name ="vs_defaultClientScript" >
< meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema" >
< SCRIPT type ="text/javascript" > <!--
function scrollDiv()
{
document.all.pos.value = document.all.onlinediv.scrollTop;//onlinediv是一个div
}
function formOnload()
{
OnloadForScroll();
}
function OnloadForScroll()
{
var spos = document.all["pos"].value;
if(! spos)spos=0;
document.all.onlinediv.scrollTop=spos;
}
--> </ SCRIPT >
</ HEAD >
< BODY onscroll ="onscrollform();" onload ="formOnload();" scroll ="no" ms_positioning ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
< table width ="300" >
< tr >
< td >
< div id ="onlinediv" style ="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 560px" onscroll ="scrollDiv();" >
<% = writebutton() %>
</ div >
</ td >
</ tr >
</ table >
< asp:textbox id ="pos" style ="DISPLAY: none" Runat ="server" ></ asp:textbox >
< asp:Button id ="Button2" style ="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 520px" runat ="server"
Text ="可以将页面缩小,把滚动条往下拉看效果" ></ asp:Button >
</ form >
</ FORM >
</ BODY >
</ HTML >
< HEAD >
< title > 窗体自身滚动条被禁止,而通过div的滚动条来定位控制 </ title >
< meta content ="Microsoft Visual Studio .NET 7.1" name ="GENERATOR" >
< meta content ="C#" name ="CODE_LANGUAGE" >
< meta content ="JavaScript" name ="vs_defaultClientScript" >
< meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema" >
< SCRIPT type ="text/javascript" > <!--
function scrollDiv()
{
document.all.pos.value = document.all.onlinediv.scrollTop;//onlinediv是一个div
}
function formOnload()
{
OnloadForScroll();
}
function OnloadForScroll()
{
var spos = document.all["pos"].value;
if(! spos)spos=0;
document.all.onlinediv.scrollTop=spos;
}
--> </ SCRIPT >
</ HEAD >
< BODY onscroll ="onscrollform();" onload ="formOnload();" scroll ="no" ms_positioning ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
< table width ="300" >
< tr >
< td >
< div id ="onlinediv" style ="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 560px" onscroll ="scrollDiv();" >
<% = writebutton() %>
</ div >
</ td >
</ tr >
</ table >
< asp:textbox id ="pos" style ="DISPLAY: none" Runat ="server" ></ asp:textbox >
< asp:Button id ="Button2" style ="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 520px" runat ="server"
Text ="可以将页面缩小,把滚动条往下拉看效果" ></ asp:Button >
</ form >
</ FORM >
</ BODY >
</ HTML >