title: Dynamically turn off Ajax Control Toolkit Autocomplete Extender
body: <p>I'm trying to dynamically enable/disable an Autocomplete extender control from the Ajax Control Toolkit based on a choice a user makes in a dropdown list.</p>
  
  <p>My ASP.NET 4.0 Webforms app has a dropdown list, and depending on which country is selected from it, the zipcode autoextender should be enabled or disabled.</p>
  
  <p>My markup:</p>
  
  <pre><code>&lt;asp:DropDownList runat="server" ID="ddlCountries"&gt;
      &lt;Items&gt;
              &lt;asp:ListItem Text="Switzerland" Value="CH" /&gt;
              &lt;asp:ListItem Text="Germany" Value="D" /&gt;
              &lt;asp:ListItem Text="Italy" Value="I" /&gt;
              &lt;asp:ListItem Text="France" Value="F" /&gt;
      &lt;/Items&gt;
  &lt;/asp:DropDownList&gt;
  &lt;br /&gt;
  
  &lt;asp:TextBox runat="server" ID="tbxZipcode" /&gt;
  
  &lt;asp:AutoCompleteExtender 
       runat="server" ID="acZipcode" BehaviorID="ZipcodeBehavior" 
       ServiceMethod="GetZipCode"
       TargetControlID="tbxZipCode" MinimumPrefixLength="1" CompletionInterval="15" 
       OnClientItemSelected="PopulateTextboxes" CompletionSetCount="25" /&gt;
  </code></pre>
  
  <p>With this setup, the autocomplete extender kicks in and displays valid Swiss zipcodes - life is good :-)</p>
  
  <p><strong>HOWEVER</strong>: if the user selects another country, I want to <strong>stop</strong> this autocomplete extender - I don't have the other zipcodes in my database to display, and displaying Swiss zipcodes for France doesn't make sense.</p>
  
  <p>So I tried something like this to grab the <code>change</code> event on the drop down list </p>
  
  <pre><code>$(document).ready(function () {
     $('#&lt;%= ddlCountries.ClientID %&gt;').change(function () {
        var chosenCountry = $(this).val();
  
        var behavior = $('#ZipcodeBehavior');
  
        if (chosenCountry == "CH") {
           behavior.disabled = '';
        } else {
           behavior.disabled = 'disabled';
        }
     });
  });
  </code></pre>
  
  <p>I can get the <code>ZipcodeBehavior</code> just fine - but once I have it - nothing seems to work anymore...</p>
  
  <p>How do I dynamically disable the Ajax Control Toolkit's AutocompleteExtender?</p>
  
  <p>In markup, statically, I do it using   </p>
  
  <pre><code>&lt;asp:AutoCompleteExtender Enabled="False" .... /&gt;
  </code></pre>
  
  <p>and then nothing at all gets rendered into my page. </p>