【问题标题】:ListBox is blocked after calling window.open()调用 window.open() 后 ListBox 被阻塞
【发布时间】:2015-05-11 01:55:36
【问题描述】:

我在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 时,一切正常。

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

【问题讨论】:

  • 您真的需要确保所选项目在列表框中可见吗?这不是默认行为吗?乍一看,代码对我来说很好

标签: javascript asp.net telerik telerik-ajax telerik-radlistbox


【解决方案1】:

确保在每次回发时注册脚本,因为提供的按钮声明将在您的主页上调用回发。如果脚本没有正确注册,您将收到脚本错误,这将解释为什么您在滚动到项目时遇到问题,以及如果您不添加处理程序,为什么事情看起来正常。 也许在标记中添加脚本块并使用服务器代码块来获取列表框 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;" />

【讨论】:

  • 非常感谢!这是我的问题,脚本没有在每个 Postback 上注册!
猜你喜欢
  • 2013-11-16
  • 2014-11-18
  • 2012-07-25
  • 1970-01-01
  • 2020-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多