Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable all checkboxes on a page 1

Status
Not open for further replies.

WalterHeisenberg

Technical User
Mar 28, 2008
159
Hello, first thanks in advance as I am a total noob to c#. I have a wizard which includes T.O.S. and once a client has completed this we mark it as such in the db. Next time they log-in they are supposed to be able to view this information but not edit it.

Right now, I have the following:

In Code Behind page:
Code:
wizardHelper.disableAll(this.Page);
In class behind:
Code:
  public void disableAll(Control ctrl)
    {
        foreach (Control c in ctrl.Controls)
        {
            if (c is CheckBox)
            {
                ((CheckBox)(c)).Checked = true;
                ((CheckBox)(c)).Enabled = false;
            }
        }
    }

Right now nothing is happening. The aspx page also uses a master page and if I do a response.write of (c) it comes back with the master page. Any help would be greatly appreciated!
 
you need to recurse through all the controls.
Code:
public void disableAll(Control ctrl)
{
   foreach (Control c in ctrl.Controls)
   {
      disableAll(c);
      if ((c is CheckBox) == false) continue;

      ((CheckBox)(c)).Checked = true;
      ((CheckBox)(c)).Enabled = false;
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thank you very much Jason! I had tried something similar but didn't have much success on my own. This did the trick!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top