【转】使用ASP.NET 2.0新增加的SetFocus和MaintainScrollPositionOnPostback增强用户体验
ASP.NET 2.0中新增加了2个很实用的属性和方法:
SetFocus()用来将光标聚焦到某个页面控件上
MaintainScrollPositionOnPostback 设置成true可以在页面PostBack的时候保持页面滚动条的位置
在web.config作如下设置即可:
SetFocus()用来将光标聚焦到某个页面控件上
<%@ page language="C#" %>
<script runat="server">
void Page_Init(object sender, EventArgs e)
{
SetFocus(focusHere);
}
</script>
<html>
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="default" runat="server" /><br />
<asp:textbox id="focusHere" runat="server" />
</form>
</body>
</html>
<script runat="server">
void Page_Init(object sender, EventArgs e)
{
SetFocus(focusHere);
}
</script>
<html>
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="default" runat="server" /><br />
<asp:textbox id="focusHere" runat="server" />
</form>
</body>
</html>
MaintainScrollPositionOnPostback 设置成true可以在页面PostBack的时候保持页面滚动条的位置
在web.config作如下设置即可:
<pages smartNavigation="true" maintainScrollPositionOnPostBack="true"/>
原文:http://www.cnblogs.com/necboy/archive/2006/02/17/332631.html