TextBox.BackColor code compiles, but doesn't do anything.

  • Thread starter Thread starter Brent
  • Start date Start date
B

Brent

It's curious. In my page the code ...


TextBox t = (TextBox)Page.FindControl(mycontrol);
if (!(t==null))
{
t.Visible = false;
}

....will hide the control. But the code...


TextBox t = (TextBox)Page.FindControl(mycontrol);
if (!(t==null))
{
t.BackColor = System.Drawing.Color.DarkRed;
}


....won't change the color.

I'd sure appreciate any tips on how to fix this behavior!

Thanks!

--Brent
 
Hi,

CSS can prevent it. check the html generated and see what you get there.
From MSDN:
Use the BackColor property to specify the background color of the Web server
control. This property is set using a System.Drawing.Color object.

Note This property will render for only certain controls. For example,
Table, Panel, DataGrid, Calendar, and ValidationSummary will render this
property. It will also work for CheckBoxList, RadioButtonList and DataList
if their RepeatLayout property is RepeatLayout.Table, not RepeatLayout.Flow.
In general, only controls that render as a <table> tag can display a
background color in HTML 3.2, whereas almost any control can in HTML 4.0.

For controls that render as a <span> tag (including Label, all validation
controls, and list controls with their RepeatLayout property set to
RepeatLayout.Flow), this property will work in Microsoft Internet Explorer
version 5 and later, but not in Microsoft Internet Explorer version 4.


You better use CSS.

cheers,
 
Back
Top