title: How do I save a checkbox value on check using ASP.net?
body: <p>I currently have a form where the user must check off checkboxes in a checkbox list before clicking a save button which saves their selections to the database. The list of values is retrieved from the database and bound to the checkbox list. So it's basically a dynamic list of checkboxes.</p>
  
  <p>I'd like to change this so that a user's selection is immediately and automatically saved to the database once the user checks off a checkbox.</p>
  
  <p>I thought this could just be done using an updatepanel, datalist, and checkboxes.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="upnlServices" runat="server" UpdateMode="Conditional"&gt;
      &lt;ContentTemplate&gt;
  
      &lt;asp:DataList ID="dlistAnimals" runat="server"&gt;
          &lt;ItemTemplate&gt;
          &lt;asp:CheckBox ID="chkAnimal" AutoPostBack="true" OnCheckedChanged="animal_click" runat="server" /&gt;
          &lt;asp:Label ID="lblAnimal" AssociatedControlID="chkAnimal" runat="server"&lt;%#Eval("Name")%&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:DataList&gt;
  
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>"animal_click" is a function in the code-behind that will add or delete the value from the database using a stored procedure. If the selection was previous selected, it is removed but if the selection does not exist in the database, it is simply added.</p>
  
  <p>This all works on my local machine but when I put it on a remote server, the form seems slow. The user will quickly check off multiple checkboxes but not all the selections were saved to the database. It gives the impression that the server isn't able to keep up with the user's actions quickly enough.</p>
  
  <p>I'm not exactly sure why this is the case. If there's a better more efficient way of doing this, I'd be interested in suggestions.</p>