Changing DetailsView controls in PreRender will fails on postbacks

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top