简体   繁体   English

maintenanceScrollPositionOnPostBack与textobox的focus方法冲突

[英]maintainScrollPositionOnPostBack clashing with focus method of textobox

I have an ASP.NET Page where in web.config I have added this setting : 我有一个ASP.NET页面,在web.config我添加了以下设置:

<pages maintainScrollPositionOnPostBack="true">

Now in a aspx page, I have a textbox (txtTop) on top of the form & after user scrolls down (there are lot of controls in between) there is a button. 现在在aspx页面中,我在窗体顶部有一个文本框(txtTop),并且在用户向下滚动(之间有很多控件)之后有一个按钮。

Inside this button Click event on Server, I have added this code. 在服务器上的此按钮Click事件中,我添加了此代码。

  txtTop.focus();

I expect that the focus should be on the textbox as well as the scroll position to be pointed towards the textbox. 我希望焦点应放在文本框上,并且滚动位置应指向文本框。 but it is not happening. 但它没有发生。 The focus is there on the textbox but it is not getting shown i have to press some key to put the textbox into the scroll position. 焦点在文本框上,但是没有显示出来,我必须按一些键才能将文本框置于滚动位置。
These two properties are clashing & I am unable to resolve it. 这两个属性发生冲突,我无法解决。

FYI: There are no update panels.. 仅供参考:没有更新面板。

I created a dirty hack to resolve this.Without setTimeout it was not working neither was document.ready. 我创建了一个肮脏的hack来解决这个问题。没有setTimeout它既没有工作也没有document.ready。

$(window).load(function () {

    setTimeout(function () {
        document.activeElement.scrollIntoView(true);
    }, 1);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM