0

I have some basic html inside an asp.net update panel. Using livequery, I set up autocomplete, blur and keydown events so that they all continue to be wired up after the update panel does a partial page load. When the page initially loads, all the events work fine but after the update panel does a partial page reload, none of the events wired up with livequery continue to work. Are there known issues with livequery and update panels?

Html:

<asp:UpdatePanel ID="upData" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:DataList ID="dlData" runat="server"
            DataSource='<%# this.Data %>' DataKeyField="ID">
            <ItemTemplate>
                <table>
                    <tr>
                        <th class="required">Location</th>
                        <td><asp:TextBox ID="txtFromLocation" MaxLength="10" CssClass="searchlocation fromlocation required" runat="server" Text='<%# Eval("FromLocation")%>'/><asp:RequiredFieldValidator ID="rvalFromLocation" runat="server"
            ControlToValidate="txtFromLocation" ValidationGroup="leg">*</asp:RequiredFieldValidator></td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
     </ContentTemplate> </asp:UpdatePanel>

And then I have my javascript. Normally it has a bunch of other code, but I can reduce it down to this and still have the problem:

$(document).ready(function() {
    $(".searchlocation").livequery(function() {                       
        $(this).keydown(function(event) {alert('test');});   

        ...

        $(this).autocomplete(...);
    });
});
Jeremy
  • 44,950
  • 68
  • 206
  • 332
  • Assuming you're using the latest version of jQuery (which you should be) you don't need jQuery.livequery any more. You can use `jQuery.live()` instead. That would be a good place to start. – Matt Ball May 03 '10 at 17:16
  • @Bears will eat you - I'm using 1.4.2. I was using jquery because I wanted to use the autocomplete function, can I use jquery live() withouth specifying an event type like I can with livequery? – Jeremy May 03 '10 at 18:27

1 Answers1

2

If you're on jQuery 1.3+, you can use .live() without any plugin, like this:

$(function() {
  $('.searchlocation').live('keydown', function(event) {
    alert('test');
  });
});
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155