This is a migrated thread and some comments may be shown as answers.

Cannot enable a checkbox via JavaScript that was disabled on the server side

2 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan Harvey
Top achievements
Rank 2
Dan Harvey asked on 30 Mar 2012, 12:17 AM
Hello,

I have disabled checkboxes within the rad grid on the server side and I am unable to enable them via javascipt.  How can this be achieved?

I use this code to enable/disable checkboxes via JavaScript
function SelectDependentRoles(checked, readerCheckbox, dropboxCheckbox) {
      if (checked) {
          readerCheckbox.checked = checked;
          readerCheckbox.disabled = true;
          dropboxCheckbox.checked = checked;
          dropboxCheckbox.disabled = true;
      }
      else {
          readerCheckbox.checked = checked;
          readerCheckbox.disabled = false;
          dropboxCheckbox.checked = checked;
          dropboxCheckbox.disabled = false;
      }
  }

This code above works just fine until i disable the checkboxes on the server:

private void EnableCheckboxes()
        {
            foreach (GridDataItem row in dgLoginRequest.MasterTableView.Items)
            {
                var chbxReader = (CheckBox)row.FindControl("chbxReader");
                var chbxRKDropbox = (CheckBox)row.FindControl("chbxRKDropbox");
                var chbxShare = (CheckBox)row.FindControl("chbxShare");
  
                chbxReader.Enabled = !chbxShare.Checked;
                chbxRKDropbox.Enabled = !chbxShare.Checked;
            
        }

Then when I try to run the javascript code it puts the checkboxes in a wierd state.  I have attached a screen shot.  How do I enable these checkboxes again via javascript?

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 04 Apr 2012, 08:52 AM
Hello,

Please note that this is e generic beahvior of the framework. No server control could be disabled on the server and enabled on the client and vice verse. This is not a valid scenario and you should enable/disable the CheckBoxes either on the server or on the client consistently.

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Robert
Top achievements
Rank 1
answered on 28 Mar 2013, 10:34 PM
http://geekswithblogs.net/jonasb/archive/2006/07/27/86498.aspx

The real problem comes when you have a checkbox like this: <asp:checkbox enabled=”false” />. This gets rendered out like this:

<span disabled='disabled'><input type='checkbox' disabled='disabled'></span>


function SelectDependentRoles(checked, readerCheckbox, dropboxCheckbox) {
      if (checked) {
          readerCheckbox.checked = checked;
   readerxCheckbox.InputAttributes.Add("disabled", "disabled");
          dropboxCheckbox.checked = checked;
          dropboxCheckbox.InputAttributes.Add("disabled", "disabled");
      }
      else {
          readerCheckbox.checked = checked;
          readerCheckbox.InputAttributes.Remove("disabled");
          dropboxCheckbox.checked = checked;
          dropboxCheckbox.InputAttributes.Remove("disabled");
      }
  }
Tags
Grid
Asked by
Dan Harvey
Top achievements
Rank 2
Answers by
Maria Ilieva
Telerik team
Robert
Top achievements
Rank 1
Share this question
or