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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make TextBoxes ReadOnly using Loop 1

Status
Not open for further replies.

RichS

Programmer
Apr 24, 2000
380
US
Is there a way in C#/ASP.NET to make all text boxes on a page ReadOnly? I have in mind to do like the following but the ReadOnly property doesn't seem to be available.
Code:
private void CCEReadOnly(Control ctlParent)
{
  foreach (Control ctlChild in ctlParent.Controls)
  {
    if (ctlChild.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
    {
      // ReadOnly property not available??
      //ctlChild.ReadOnly = true;
    }
        
    // Check for more children
    if (ctlChild.Controls.Count > 0)
    {          
      CCEReadOnly(ctlChild);          
    }
  }
}
 
You probably need to cast it to System.Web.UI.WebControls.Textbox before attempting to set the readonly property.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top