Postback checkbox asp.net with Plugin Switchery

1

I'm putting together a list of records in a table with asp.net. I create for each line a checkbox to perform an action through postback every time the checkbox is checked or unchecked. I use the Switchery plugin to style this checkbox, but when I click on the switch (action same as ticking / unchecking the checkbox), it does not perform the postback. If I comment the line with the default class used by the plugin or change the class name (thus leaving the "raw" checkboxes in the table) the postback works correctly.

Switch creation JS code

 var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
            elems.forEach(function (html) { 
                var switchery = new Switchery(html); 
            });

C # code

CheckBox lkBtnExcluir = new CheckBox();
                        lkBtnExcluir.ID = dr["empr_codigo"].ToString() + "_id"; 
                        lkBtnExcluir.AutoPostBack = true;
                        lkBtnExcluir.Attributes.Add("USUARIO", dr["COD_USUARIO"].ToString());
                        lkBtnExcluir.InputAttributes.Add("class", "js-switch");
                        //lkBtnExcluir.CssClass = "js-switch";

                        if (dr["usa_atend"].ToString() == "S")
                        {
                            lkBtnExcluir.Checked = true;
                            lkBtnExcluir.Attributes.Add("STATUS", "N"); 
                        }
                        else
                        {
                            lkBtnExcluir.Attributes.Add("STATUS", "S"); 
                        }

                        lkBtnExcluir.CheckedChanged += new EventHandler(mudarStatus_click);
                        tdAcao_.Controls.Add(lkBtnExcluir);
    
asked by anonymous 13.02.2015 / 18:10

1 answer

0

I was able to fix it. If someone has the same problem I had, follow an Javascript event to force the PostBack :

  <script>
  $(".js-switch").change(function () {
            __doPostBack($(this).attr("id"), '');
        });
  </script>
    
13.02.2015 / 18:54