设置值时页面移位 - 我的代码或最新版Chrome中的错误?

时间:2014-10-30 12:35:02

标签: asp.net google-chrome

在我解释我的问题之前的一些背景信息。这在任何其他测试的浏览器中都不会发生(IE,FireFox,Safari,甚至是旧版本的chrome),但就在上周,我和我的几个最终用户chrome自动更新为版本:

Version 38.0.2125.111 m

我开始使用我编写的应用程序接听电话和电子邮件,当它最初加载一些页面加载并且页面滚动到底部,中间而其他页面很好。 我无法理解为什么会发生这种情况,因为它过去从未发生在Chrome中,并且在任何其他浏览器中都没有发生。我检查了开发人员工具,没有js / jquery问题。

我决定今天花更多的时间在上面,我最初做的是找出它发生了哪些页面,因为它并没有发生在我的所有aspx页面上。然后它发生的事情我想找到它们之间的共同点。

来查看我的页面加载事件中发生了什么我加载了一些初始下拉列表/列表框值。现在,在加载它之后,在其中一个列表框中,我将其设置为初始值,就像这样简单:

lbCustomers.Items.FindByValue("SomeDefault").Selected=true;

在页面完全加载chrome之后,无论页面上的控件是何处,都会将您带到控件所在页面的那一部分。几乎就像是把重点放在控制上。我可以通过将焦点放在页面顶部的某个控件上来轻松地修复/破解它,但这只是感觉不对。

因此,假设您在页面上有一大堆下拉控件,实际上您有很多页面要求您垂直滚动。如果我设置说最后一个下拉控件(位于页面底部),页面将加载并将转到页面底部。然后我查看了它将打开到页面中间的页面,当然,我正在使用默认值分配位于页面中间的控件。

这是一个使用jquery的asp.net web表单项目,我们也使用所选的库...任何人都可以在最新版本的chrome中确认这一点,或者我只是做错了什么?我所做的一切只是设置一个下拉列表或列表框值:

myDropDown.Items.FindByValue("1").Selected=true;

Chrome会直接在我设置此下拉/列表框的位置打开页面。

更新

经过进一步测试后,我继续创建了一个测试aspx页面,其中包含一个下拉列表和一个列表框。我也都应用了所选的库。看起来设置下拉框通常可以正常工作。但是,当我加载并选择列表框时,问题就在这里。所以我决定尝试一个常规列表框(没有选择应用)......同样的事情。

所以这个问题似乎与列表框有关(无论如何使用像你选择的库或者你只是使用标准的aspx列表框)。无论何时在代码后面设置列表框,它都会将页面移动到该列表框控件所在的位置。

作为测试

今天早上我创建了一个简单的aspx页面测试。 我添加了一大堆文本和4个控件。

  • 我添加的一个控件是标准的asp.net下拉列表
  • 我添加的第二个控件是标准的asp.net列表框
  • 我添加的第三个控件是使用所选库
  • 的下拉列表
  • 我添加的第四个控件是使用所选库
  • 的列表框控件

当我为任何下拉列表设置所选值时(无论是标准还是选择),正常页面加载发生,它会正确加载到顶部。

当我为任何列表框设置所选值时(无论我使用选择列表框还是标准列表框),这里是问题发生的地方。该页面将加载到该位置 列表框的位置。所以这似乎是一般的列表框铬的错误?

测试我跑

只需将一些文本(很多文本)和一个列表框控件添加到aspx页面,如下所示:

 The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stickThe brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    The brown fox jumped over the candle stick
    <br/><br/><br/>
                    <asp:ListBox ID="ListBox1" runat="server">
                        <asp:ListItem>1</asp:ListItem>
    </asp:ListBox>

现在在你的页面加载事件中输入:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ListBox1.Items.FindByValue("1").Selected = true;   
            }
        }

在Chrome版本38.0.2125.111 m中打开此页面,您是否看到同样的问题?在IE或firefox中打开工作正常。在以前版本的chrome中打开工作正常,它只有这个版本38.0.2125.111 m。

有人可以复制吗?

1 个答案:

答案 0 :(得分:1)

很明显问题出在Chrome上,而不是ASP.NET,因为可以使用以下HTML文档进行复制:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>ListBox Test</title>
  </head>
  <body>
    <p style="margin-bottom: 200em;">Name: <input type="text"></p>
    <select size="5">
      <option selected value="A">Apple</option>
    </select>
  </body>
</html>

作为一种变通方法,您可以在早期输入字段上添加autofocus属性(如果有):

<p style="margin-bottom: 200em;">Name: <input type="text" autofocus></p>