ListBox 在调用 window.open() 后被阻塞

ListBox is blocked after calling window.open()

我在Page_Load()中注册了以下JavaScript:

var scriptReihe = "<script type=\"text/javascript\">function OnClientLoadHandlerReihe(sender) {"
                     + "var listbox = $find(\"" + lbReihen.ClientID + "\");"
                     + "var item = listbox.get_selectedItem();"
                     + "item.ensureVisible();"
                     + "}"
                     + "</script>";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnClientLoadHandlerReihe", scriptReihe);
lbReihen.OnClientLoad = "OnClientLoadHandlerReihe";

其中 lbReihenRadListBox

效果很好,selectedItem 位于列表框的可见区域。

页面上还有一个按钮:

<asp:Button ID="myBtn" runat="server" Text="Call google" OnClientClick="window.open('http://www.google.ch', '_blank');" />

现在的问题是,当单击按钮并打开新页面(在新选项卡中)时,我的 ListBox 被阻止了。我无法在其中滚动等等

当我没有为 OnClientLoad 注册 EventHandler 时,一切正常。

谁能给我一个提示,有什么问题吗? - 谢谢。

确保在每次回发时注册脚本,因为提供的按钮声明将在您的主页上调用回发。如果脚本没有正确注册,您将收到脚本错误,这将解释为什么您在滚动到该项目时遇到问题,以及为什么如果您不添加处理程序则一切正常。 也许在标记中添加脚本块并使用服务器代码块来获取列表框 ID 更容易,例如:

        <telerik:RadListBox ID="lbReihen" runat="server"></telerik:RadListBox>
        <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
            <script type="text/javascript">
                function OnClientLoadHandlerReihe(sender) {
                    var listbox = $find("<%=lbReihen.ClientID%>");
                    var item = listbox.get_selectedItem();
                    item.ensureVisible();
                }
            </script>
        </telerik:RadCodeBlock>

此外,考虑通过返回 false 来防止按钮回发:

<asp:Button ID="myBtn" runat="server" Text="Call google" OnClientClick="window.open('http://www.google.ch', '_blank'); return false;" />