Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top