1

I have a multiple check box in a grid. my code sample is as follows:

<asp:Panel ID="FeatureGridViewPanel" runat="server" Visible="true" Width="100%">
    <div class="topline"></div>
    <div class="linebreak"></div>
    <div style="float:left; width:90%;">
        <asp:GridView ID="FeatureListGridView" runat="server" AutoGenerateColumns="False"
        CellPadding="4" ForeColor="#666666" GridLines="None" Width="100%">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:Label ID="FeatureNameHeaderLabel" runat="server" Text="Feature Name "
                        CssClass="GridViewTH"></asp:Label>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div style="display: none;">
                            <asp:Label ID="FeatureIDLabel" runat="server" Text='<%#Eval("FeatureID")%>'>' ></asp:Label>
                        </div>
                        <asp:Label ID="FeatureNameLabel" runat="server" CssClass="GridViewLabel"
                        Text='<%#Eval("FeatureName")%>'>' ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:Label ID="FeatureStatusHeaderLabel" runat="server" Text="Feature Status"
                        Class="GridViewTH"></asp:Label>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="FeatureStatusCheckBox" runat="server" Checked='<%#Eval("isEnabled") %>'
                        />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EditRowStyle />
        </asp:GridView>
    </div>
    <div class="topline"></div>
    <div class="linebreak"></div>
    <div style="margin:4px; float:right;">
        <asp:Button ID="CancelAllChagesButton" runat="server" Text="Cancel All Changes"
        OnClick="CancelAllChagesButton_Click" CssClass="CCButtonEnabled" />
        <asp:Button ID="SaveAllChangesButton" runat="server" Text="Save All Changes"
        OnClick="SaveAllChangesButton_Click" CssClass="CCButtonEnabled" />
        <asp:Button ID="ChangePlanButton" runat="server" Text="Change Plan" OnClick="ChangePlanButton_Click"
        CssClass="CCButtonEnabled" />
        <asp:Button ID="UpgradeFeatureButton" runat="server" Text="Update Feature"
        OnClick="UpgradeFeatureButton_Click" CssClass="CCButtonEnabled" />
    </div>
</asp:Panel>

i just want to disable the SaveAllChangesButton and CancelAllChagesButton if there is no changes. i want to enabled the SaveAllChangesButton and CancelAllChagesButton when there is changes in the checkbox. to do so I have a jquery code like this:

  $(document).ready(function () {
      $('[id$=SaveAllChangesButton]').attr('disabled', 'disabled');
      $('[id$=CancelAllChagesButton]').attr('disabled', 'disabled');
      $(".disabled").click(function () {
          return false;
      });
      $('[id$=FeatureStatusCheckBox]').click(function () {

          $('[id$=CancelAllChagesButton]').removeAttr('disabled', 'disabled');
          $('[id$=SaveAllChangesButton]').removeAttr('disabled', 'disabled');

      });
  });

When there is no changes it is working fine, but when there is changes in some of the checkbox then the SaveAllChangesButton and CancelAllChagesButton should be enabled but here in my condition this buttons are not enabled. And when User clicks on CancelAllChagesButton then the SaveAllChangesButton and CancelAllChagesButton should be disable. How can I achieve this?

3 Answers 3

1

Try this

$(document).ready(function () {
   $('input[id$="SaveAllChangesButton"]').prop('disabled', true);
   $('input[id$="CancelAllChagesButton"]').prop('disabled', true);

   $(".disabled").click(function () { return false; });
   $('input[id$="FeatureStatusCheckBox"]').click(function () {

         $('input[id$="CancelAllChagesButton"]').removeAttr('disabled');
         $('input[id$="SaveAllChangesButton"]').removeAttr('disabled');

   });
});
Sign up to request clarification or add additional context in comments.

3 Comments

it should be prop('disabled', true/false);
The buttons are not enabled in the checked event of checkbox. again the same result.
only the document.ready section is executed. It doesnot fire the $('[id$=FeatureStatusCheckBox]').click(function ()
1

Bind your checkbox to the change event instead of click, and set the disabled property, not the attribute. You shouldn't need this input[id$=""] part in the selectors. You could instead do it like this. Much simpler. Here's a jsFiddle that demonstrates this: http://jsfiddle.net/xXfUp/

$(document).ready(function () {
  var check = $('#FeatureStatusCheckBox'),
      save = $('#SaveAllChangesButton'),
      cancel = $('#CancelAllChagesButton');

  save.prop('disabled', true);
  cancel.prop('disabled', true);

  check.change(function () {
    if ($(this).prop('checked')) {
      save.prop('disabled', false);
      cancel.prop('disabled', false);
    } else {
      save.prop('disabled', true);
      cancel.prop('disabled', true);
    }
  });
});

Comments

1

You Can Do Like This:

 $(document).ready(function () {
 var check = $('[id$=FeatureStatusCheckBox]'),
  save = $('[id$=SaveAllChangesButton]'),
  cancel = $('[id$=CancelAllChagesButton]');

  save.prop('disabled', "Disabled");
  cancel.prop('disabled', "Disabled");

  check.change(function () {
  if ($(this).prop('checked')) {
  save.prop('disabled', "Disabled");
  cancel.prop('disabled', "Disabled");
  } 
  else {
  save.prop('disabled', "Disabled");
  cancel.prop('disabled', "Disabled");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.