.NET 更新面板 +实时查询

发布于 2024-09-18 18:31:38 字数 564 浏览 2 评论 0原文

我使用 LiveQuery 来检测元素何时添加到页面。该元素位于 .NET AJAX UpdatePanel 内。刷新 UpdatePanel 时,实时查询不会检测到新元素。

        <asp:UpdatePanel runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="refresh" />
        </Triggers>
        <ContentTemplate>
            <a id="but1" href="#">Button 1</a> 
        </ContentTemplate>
    </asp:UpdatePanel>


 $('#but1').livequery(function(event) {
        alert('Button added');
    });

仅当页面首次加载时才会触发警报。刷新 udpatepanel 时不会。

I have used LiveQuery to detect when an element is added to the page. The element is inside an .NET AJAX UpdatePanel. When the UpdatePanel is refreshed, live query does not detect the new element.

        <asp:UpdatePanel runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="refresh" />
        </Triggers>
        <ContentTemplate>
            <a id="but1" href="#">Button 1</a> 
        </ContentTemplate>
    </asp:UpdatePanel>


 $('#but1').livequery(function(event) {
        alert('Button added');
    });

The alert only fires when the page is first loaded. Not when the udpatepanel is refreshed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南街九尾狐 2024-09-25 18:31:39

Live Query 仅在通过 jQuery DOM 操作机制进行更改时才能看到您的更改。在这个答案中类似问题,我努力解决这个问题并提出了一种基于轮询的解决方法。

Live Query only sees your changes when they are made through the jQuery DOM manipulation mechanisms. In this answer to a similar question, I struggled with this problem and suggested a polling-based workaround.

囚我心虐我身 2024-09-25 18:31:39

尝试将 jquery 代码包装在 pageLoad 中,如下所示:

function pageLoad()
{
    $(document).ready(function () {
        $('[id$=but1]').livequery(function(event) {
            alert('Button added');
        });
    });
}

您需要在 ScriptManager 标记中添加 EnablePageMethods="true" :

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

try wrapping the jquery code inside pageLoad like this:

function pageLoad()
{
    $(document).ready(function () {
        $('[id$=but1]').livequery(function(event) {
            alert('Button added');
        });
    });
}

You will need to add the EnablePageMethods="true" inside your ScriptManager tag:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文