加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 设置值时页面移位 – 我的代码或最新版本的Chrome中

发布时间:2020-12-16 09:40:56 所属栏目:asp.Net 来源:网络整理
导读:在我解释我的问题之前的一些背景信息.这不会发生在任何其他测试的浏览器(IE,FireFox,Safari,甚至旧版本的chrome)中,但就在上周我和我们的几个最终用户chrome自动更新到版本: 版本38.0.2125.111 m 我开始接到电话和电子邮件,我写了一个应用程序,当它最初加载
在我解释我的问题之前的一些背景信息.这不会发生在任何其他测试的浏览器(IE,FireFox,Safari,甚至旧版本的chrome)中,但就在上周我和我们的几个最终用户chrome自动更新到版本:

版本38.0.2125.111 m

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

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

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

.lbCustomers.Items.FindByValue( “SomeDefault”)选定= TRUE;

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

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

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

myDropDown.Items.FindByValue( “1”)选定=真.

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.

有人可以复制吗?

解决方法

很明显,问题在于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>

作为一种变通方法,您可以将自动对焦属性放在较早的输入字段上(如果有):

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读