title: Disabling Checked checkboxes in a Repeater when clicking a Submit button
body: <p>I would like to disable Checked checkboxes when the user clicks the Submit button in ASP.NET.  I can disable the checkboxes using JavaScript using the onclick event of the button.  The checkboxes are in a Repeater.  When the form is submitted by clicking the Submit button, none of the checkboxes show as checked in the code-behind button click code.  How can I disable Checked checkboxes when the submit button is clicked and still see that the checkboxes are Checked when the page is submitted?  Is there a work around?  My preference would be to do this in JavaScript but I'm willing to use jQuery as well.</p>
  
  <pre><code>function disableCheckboxes() {
      for (var count = 0; i &lt; document.forms[0].elements.length; i++) 
      {
          if (document.forms[0].elements[count].type == 'checkbox')
          {
              document.forms[0].elements[count].disabled = true;
          }
      }
  }
   &lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &lt;table&gt;
  
          &lt;asp:Repeater ID="rptCustomer" runat="server" OnItemDataBound="DisplayCustomerRepeater_ItemDataBound"&gt;
              &lt;ItemTemplate&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;asp:CheckBox ID="checkSubscription" runat="server" /&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;%# ((Customer)Container.DataItem).FirstName + " " + ((Customer)Container.DataItem).LastName%&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;hr /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:Repeater&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;asp:Button ID="btnSubmit" OnClick="btnSubmit_Click"
          Text="Submit" runat="server" /&gt;&lt;/div&gt;
  &lt;/form&gt;
  
  protected void Page_Load(object sender, EventArgs e)
  {
      if (!this.IsPostBack)
      {
          rptCustomer.DataSource = customers;
          rptCustomer.DataBind();
      }
  
      btnSubmit.Attributes.Add("onclick", String.Concat("this.disabled=true;disableCheckboxes();", ClientScript.GetPostBackEventReference(btnSubmit, "")));
  }
  protected void DisplayCustomerRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
  {
      ListItemType lt = e.Item.ItemType;
      if (lt == ListItemType.Item || lt == ListItemType.AlternatingItem)
      {
          Customer customer = e.Item.DataItem as Customer;
          if (customer != null)
          {
              CheckBox chkCustomer = e.Item.FindControl("checkSubscription") as CheckBox;
              if (chkCustomer != null)
              {
                  if (customer.IsEligible)
                  {
                      chkCustomer.Checked = true;
                  }
              }
          }
      }
  }
  protected void btnSubmit_Click(object sender, EventArgs e)
  {
      bool isChecked = false;
  
      foreach (RepeaterItem item in rptCustomer.Items)
      {
          CheckBox selectedCheckBox = (CheckBox)item.FindControl("checkSubscription");
          if (selectedCheckBox.Checked)
          {
              isChecked = true;
          }
      }
  }
  </code></pre>