ASP.NET AJAX UpdatePanel滚动问题 [英] ASP.NET AJAX UpdatePanel scrolling problem

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

问题描述

我会尽量简洁:

  1. 我有一个下拉列表,其中Autopostback设置为true
  2. 我有一个包含Label的UpdatePanel.
  3. 更改下拉列表选择时,我要更新标签.

问题:焦点丢失在下拉列表上,迫使用户单击下拉列表以将焦点重新设置为控件.

我的解决方案":在DropDownList_SelectionChanged事件中,将焦点设置回下拉列表:

dropdownlist1.focus()

虽然这在IE中非常有效,但Firefox和Chrome会更改滚动位置,以使分配焦点的控件位于浏览器窗口可见部分的底部.这通常是一个非常令人迷惑的副作用.

如何避免这种情况,使其在FF中像在IE中一样起作用?

解决方案

尝试使用以下三种方法之一维护 MaintainScrollPositionOnPostback

  • 以编程方式-Page.MaintainScrollPositionOnPostBack = true;
  • 页面声明-<%@页面MaintenanceScrollPositionOnPostback ="true"%>
  • 在web.config中-<页面maintenanceScrollPositionOnPostBack ="true"/>

您可能还需要在scriptmanager声明之后添加以下javascript:

<script type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_beginRequest(beginRequest);

function beginRequest()
{
    prm._scrollPosition = null;
}

</script> 

I'll try and be concise:

  1. I have a dropdownlist with Autopostback set to true
  2. I have an UpdatePanel that contains a Label.
  3. When the downdownlist selection is changed, I want to update the label.

Problem: Focus is lost on the dropdownlist, forcing the user to click on the dropdownlist to reset focus back to the control.

My "solution": In the DropDownList_SelectionChanged event, set focus back to the drop down list:

dropdownlist1.focus()

While this works great in IE, Firefox and Chrome change the scroll position such that the control which was assigned focus is positioned at the bottom on the visible portion of the browser window. This is often a very disorientating side effect.

How can this be avoided so it works in FF as it does in IE?

解决方案

Try MaintainScrollPositionOnPostback in one of these 3 ways

  • Programmatically - Page.MaintainScrollPositionOnPostBack = true;
  • Page declaration - <%@ Page MaintainScrollPositionOnPostback="true" %>
  • In the web.config - <pages maintainScrollPositionOnPostBack="true" />

You may also need to add this javascript after the scriptmanager declaration:

<script type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_beginRequest(beginRequest);

function beginRequest()
{
    prm._scrollPosition = null;
}

</script> 

这篇关于ASP.NET AJAX UpdatePanel滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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