在页面编写的时候,经常会遇到页面过长,每次点击按钮时,页面会置顶的情况,所以写了一个小方法,可以使页面跳转,方法虽小,但很实用;
方法如下:
public static void BackPage(System.Web.UI.Page thePage, object sender)
{
string szValue = string.Format("window.location.href='#{0}'",((System.Web.UI.Control)sender).ID);
AddEvent(thePage,"onload",szValue);
}在页面上还要把Body设置一下,以及调用方法
<body id="body" runat="server">//设置Body
BackPage(this,sender);//sender也可以换成控件名称
//在上面代码中用到了AddEvent方法如下
public static void AddEvent(System.Web.UI.Page thePage, string szKey, string szValue)
{
string szScript = @"
<script>
window.document.body."+szKey+@"= function()
{
"+szValue+@"
}
</script>
";
thePage.RegisterClientScriptBlock("Js",szScript);
} 

以上是一些小技巧,拿出来大家分享一下,有待高人指教


浙公网安备 33010602011771号