Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I save a checkbox value on check using ASP.net?
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload