Changing DetailsView controls in PreRender will fails on postbacks

  • Thread starter Thread starter Khafancoder
  • Start date Start date
K

Khafancoder

Hi guys,

i'm trying to change all of page control's (root controls and inner
controls) forecolor in PreRender event.
it works fine but when a postback occures by detailsview command
buttons, it fails...

(i trace the code, it even executes in postbacks but control's
forecolor don't change)

i use this code :

Code:
protected override void OnPreRender(EventArgs e)
{
ChangeColor(this.Controls);

base.OnPreRender(e);

}


private void ChangeColor(ControlCollection controls)
{

foreach (Control c in controls)
{
if (c.HasControls())
ChangeColor(c.Controls);
else if (c is DetailsView)
{
DetailsView view = c as DetailsView;
foreach (DetailsViewRow row in view.Rows)
{
ChangeColor(row.Controls);
}
}
else
{
if (c is WebControl) ((WebControl)c).ForeColor =
System.Drawing.Color.DeepPink;
}

}
}

Thanks
 
Back
Top