Firefox“;“跳跃”;在<;中使用UpdatePanel和SetFocus时;iframe>;(asp.net)

Firefox“;“跳跃”;在<;中使用UpdatePanel和SetFocus时;iframe>;(asp.net),asp.net,Asp.net,如果我在iframe中同时使用UpdatePanel和SetFocus函数,那么Firefox就会“跳转”(将滚动条移到顶部)。我将通过发布代码来显示这一点: 首先,Web表单的HTML: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C/

如果我在iframe中同时使用UpdatePanel和SetFocus函数,那么Firefox就会“跳转”(将滚动条移到顶部)。我将通过发布代码来显示这一点:

首先,Web表单的HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem>1</asp:ListItem>
                    <asp:ListItem>2</asp:ListItem>
                    <asp:ListItem>3</asp:ListItem>
                    <asp:ListItem>4</asp:ListItem>
                    <asp:ListItem>5</asp:ListItem>
                </asp:DropDownList>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
好的,这个表单托管在一个使用iframe的裸体HTML页面中。以下是HTML主机页:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<div>
        bla bla bla
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <iframe src="WebForm1.aspx" style="height: 1263px; width: 1254px"></iframe>
    </div>

</body>
</html>

呜呜呜呜


























我添加了br元素,因为需要滚动条才能看到效果。现在,如果您在主机页中向下滚动,并在Internet Explorer的iframe中的dropdownlist中选择一个值,则标签将在没有任何问题的情况下更新,dropdownlist将获得焦点

现在在Firefox中尝试同样的方法-一切都可以正常工作,但是Firefox会再次将html主机页面滚动到顶部,这是一种恼人的效果

我尝试了更大的页面和多个iframe,它似乎滚动到一个iframe的开头,在其中您选择了dropdownlist中的值。Safari(我猜Chrome)也有同样的行为。Opera不会做这种恼人的“跳跃”(IE也一样)


这里有什么问题?

好的,经过大量搜索,我找到了解决方案:

用户“dotnetseek”在该线程中拥有正确的解决方案

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<div>
        bla bla bla
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <iframe src="WebForm1.aspx" style="height: 1263px; width: 1254px"></iframe>
    </div>

</body>
</html>