S
Steve
I'm trying to iterate over all the form controls in my MasterPages content
page. Basically, I've got dropdowns, textboxes, etc that I want to format
in Page_Load()
I've added this code to my Page_Load() event
<code>
private void ConfigureFormControls()
{
Color borderColor = ColorTranslator.FromHtml("#F5F5F5");
Color fontColor = borderColor;
Color backgroundColor = ColorTranslator.FromHtml("#0D0D0D");
foreach(Control control in this.Controls)
{
if(control is TextBox || control is DropDownList || control is
Button)
{
WebControl webControl = control as WebControl;
webControl.BorderStyle = BorderStyle.Solid;
webControl.BorderWidth = 1;
webControl.BorderColor = borderColor;
webControl.ForeColor = fontColor;
webControl.BackColor = backgroundColor;
}
}
}
</code>
Problem is, the 'this.Controls' collection only has a count of 1, but I have
over 45 textboxes alone! So obviously, I'm hitting the wrong collection,
but as I inspected this.Controls while debuggin I didn't understand how I
was looking at a MasterPage control as the only control in the collection.
I'm sure one of you know exactly what I'm doing wrong, I would really
appreciate a tip.
BTW, I'm not too skilled in the ol' CSS yes, that's why I'm doing it this
way. I can get the dropdowns to work with my CSS, but the textboxes refuse.
Just for kicks, here is my CSS:
..input, select
{
background: #1E1E1E;
color: #F5F5F5;
border: 1px solid #F5F5F5;
}
Thanks for reading,
Steve
page. Basically, I've got dropdowns, textboxes, etc that I want to format
in Page_Load()
I've added this code to my Page_Load() event
<code>
private void ConfigureFormControls()
{
Color borderColor = ColorTranslator.FromHtml("#F5F5F5");
Color fontColor = borderColor;
Color backgroundColor = ColorTranslator.FromHtml("#0D0D0D");
foreach(Control control in this.Controls)
{
if(control is TextBox || control is DropDownList || control is
Button)
{
WebControl webControl = control as WebControl;
webControl.BorderStyle = BorderStyle.Solid;
webControl.BorderWidth = 1;
webControl.BorderColor = borderColor;
webControl.ForeColor = fontColor;
webControl.BackColor = backgroundColor;
}
}
}
</code>
Problem is, the 'this.Controls' collection only has a count of 1, but I have
over 45 textboxes alone! So obviously, I'm hitting the wrong collection,
but as I inspected this.Controls while debuggin I didn't understand how I
was looking at a MasterPage control as the only control in the collection.
I'm sure one of you know exactly what I'm doing wrong, I would really
appreciate a tip.
BTW, I'm not too skilled in the ol' CSS yes, that's why I'm doing it this
way. I can get the dropdowns to work with my CSS, but the textboxes refuse.
Just for kicks, here is my CSS:
..input, select
{
background: #1E1E1E;
color: #F5F5F5;
border: 1px solid #F5F5F5;
}
Thanks for reading,
Steve