Aidan Garnish

Collaboration Not Competition

An efficient way to set web control values

Rather than setting the widths of label and textbox controls individually like this:




It is much more efficient to add the controls to the controls collection and use:

foreach(Control oControl in this.Controls)
     if (oControl.GetType().ToString() == "System.Web.UI.WebControls.Label")
       Label oLabel = (Label)oControl;
       oLabel.Width = 120;

This then allows you to change the widths of all your labels within the page or web part in one place. This approach can also be taken with other controls like text boxes and drop downs or could be used to set other properties such as font or color.

Or you could just use CSS.  Smile

Add comment