<%
int pos=0;if (Request["__SCROLLPOS"] != null && Request["__SCROLLPOS"] != String.Empty)
{
try
{
pos = Convert.ToInt32 (Request["__SCROLLPOS"]);
}
catch {}
}if (pos > 0)
{
Response.Write ("<body id=\"theBody\" " +
"onscroll=\"javascript:document.forms[0].__SCROLLPOS.value = " +
"theBody.scrollTop;\" " +
"onload=\"javascript:theBody.scrollTop=" + pos + ";\">");
}
else
{
Response.Write ("<body id=\"theBody\" " +
"onscroll=\"javascript:document.forms[0].__SCROLLPOS.value =" +
"theBody.scrollTop;\">");
}
%>
int pos=0;if (Request["__SCROLLPOS"] != null && Request["__SCROLLPOS"] != String.Empty)
{
try
{
pos = Convert.ToInt32 (Request["__SCROLLPOS"]);
}
catch {}
}if (pos > 0)
{
Response.Write ("<body id=\"theBody\" " +
"onscroll=\"javascript:document.forms[0].__SCROLLPOS.value = " +
"theBody.scrollTop;\" " +
"onload=\"javascript:theBody.scrollTop=" + pos + ";\">");
}
else
{
Response.Write ("<body id=\"theBody\" " +
"onscroll=\"javascript:document.forms[0].__SCROLLPOS.value =" +
"theBody.scrollTop;\">");
}
%>
Web窗体:如何保持窗体滚动条的当前位置?
文章地址:
http://www.wintellect.com/resources/faqs/default.aspx?faq_id=1&page=7
标题:
Is it possible to prevent a Web form from scrolling to the top of the page when it posts back to the server? 另外这个程序的原理你能不能给我解释一下,先谢谢了。
在HTML文本里:
1.紧跟<body></body>标记之间,<body>标记后面添加:你的那段代码!
2.在<form></form>标记之间,紧跟<form>标记添加:
<input type="hidden" name="__SCROLLPOS" value="" />
两条就行了!