ASP.net回发 - 滚动到特定位置 [英] ASP.net Postback - Scroll to Specific Position

查看:114
本文介绍了ASP.net回发 - 滚动到特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了在屏幕顶部的很多内容的ASP.net WebForms的页面。它有一个链接按钮,将回发到网页,并显示在页面的另一部分。当页面刷新,我想设定对焦和向下滚动到页面的这个部分。

I have an ASP.net WebForms page that has a lot of content on the top of the screen. It has a link button that will post back to the page and show another section of the page. When the page refreshes, I would like to set focus and scroll down to this section of the page.

我试图做

txtField.Focus()

在我的背后code,它会设定对焦和设法在那里滚动,但滚动右后卫顶端。重点仍然是在我的文本框,但屏幕的位置是在最高层。领汇是指导致回发的屏幕的顶部。我想滚动到屏幕的底部。为此,它会短暂地,然后滚动右后卫的顶端。

in my code behind and it will set focus and try to scroll there, but then scrolls right back to the top. The focus is still on my text box but the position of the screen is at the very top. The Link is at the top of the screen which is causing the postback. I want to scroll to the very bottom of the screen. It does this briefly and then scrolls right back to the top.

我已经尝试设置

Page.MaintainScrollPositionOnPostback = false;

但是这似乎并没有帮助的。

but that doesn't seem to help either.

有没有一些方法,我可以强制它去到一个特定的位置?
是否有可能一个锚定标记添加到URL,当我回发使用一个按钮或链接按钮?

Is there some way I can force it to go to a specific position? Is it possible to add an anchor tag to the URL when I postback using a button or link button?

推荐答案

Page.MaintainScrollPositionOnPostBack = TRUE; 应该带你回到屏幕上的同一位置,但你可以使用AJAX,或者你可以使用 SetFocus的()专注于后回传特定的控制:

Page.MaintainScrollPositionOnPostBack = true; should take you back to the same position on the screen, but you could use AJAX, or you could use SetFocus() to focus on a specific control after the postback:

http://msdn.microsoft.com/en-us/library/ ms178232.aspx

这篇关于ASP.net回发 - 滚动到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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