下一页是在asp.net向下滚动 [英] The next Page is scrolled down in asp.net

查看:151
本文介绍了下一页是在asp.net向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在asp.net 2的网页,vb.net是code后面。当我在一个页面点击下一步按钮应该出现在第二页。第二页是巨大的,当我点击下一步按钮,页面即将到来,但它的重点是底部,为了去顶,我需要使用滚动,我想要的是让焦点之上。

I have two webpages written in asp.net, vb.net is code behind. When I click on next button in one page the second page should appear. The second page is huge one, when I click on the next button, the page is coming, but its focus is bottom, in order to go top, I need to use the scrolling, what I want is to make the focus top.

推荐答案

您可以使用此的脚本,以便你的页面将滚动到你的页面上的特定控制。

You can use this script so that your page will be scrolled to a specific control on your page.

在code应该把你的codeBehind。
只要选择一些控制,在你的页面的顶部,它应该做的工作。

The code should be put in your CodeBehind. Just choose some control which is at the top of your page and it should do the work..

我要指出,有你的页面滚动的底部是一个不寻常的行为,不应该被默认发生。你或许应该检查为什么发生在首位。

I should note that having your page scroll to the bottom is an unusual behavior and shouldn't be happening by default. You should probably check why it's happening in the first place.

更新:

更新了code,因为所采用的方法有过时...

Updated the code since the method used there is obsolete...

private void FocusControlOnPageLoad(string ClientID)
{

            ClientScript.RegisterClientScriptBlock(this.GetType(), "FocusOnControl",

            @"<script> 

              function ScrollView()

              {
                 var el = document.getElementById('" + ClientID + @"')
                 if (el != null)
                 {        
                    el.scrollIntoView();
                    el.focus();
                 }
              }

              window.onload = ScrollView;

              </script>");

}

用法:

protected void Page_Load(object sender, EventArgs e)
{
    FocusControlOnPageLoad(yourcontrol.ClientID); 
}

等效VB.Net:(感谢@Mahyar)

Equivalent VB.Net: (Thanks to @Mahyar)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    FocusControlOnPageLoad(yourcontrol.ClientID)
End Sub
Private Sub FocusControlOnPageLoad(ByVal ClientID As String)
    Dim script As String = _
        "<script>" + _
            "function ScrollView()" + _
            "{" + _
                "var el = document.getElementById('" + ClientID + "')" + _
                "if (el != null)" + _
                "{" + _
                "el.scrollIntoView();" + _
                "el.focus();" + _
                "}" + _
            "}" + _
            "window.onload = ScrollView;" + _
        "</script>"
    ClientScript.RegisterClientScriptBlock(Me.GetType(), "FocusOnControl", script)
End Sub

这篇关于下一页是在asp.net向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆