I want to be able to skin my Telerik RadControls on my asp.net page on the fly.
To do this I've made sure all these controls have an ID that starts "Rad" and when the page loads I have a method that cycles through all controls on a page and creates a List<Control> of those starting with "Rad".
Now all I need to do is cycle through my list and set the skin property to my selected skin. However, Control has no concept of "Skin" so I am trying to cast each of these to RadControl but am getting errors when casting, such as
Unable to cast object of type 'Telerik.Web.UI.RadPanelBar' to type 'Telerik.Web.UI.RadControl'.
My Code below...
I suppose I could pass the skin name across and set the skin in the LoopControls method, but would still like an answer to my question.
To do this I've made sure all these controls have an ID that starts "Rad" and when the page loads I have a method that cycles through all controls on a page and creates a List<Control> of those starting with "Rad".
Now all I need to do is cycle through my list and set the skin property to my selected skin. However, Control has no concept of "Skin" so I am trying to cast each of these to RadControl but am getting errors when casting, such as
Unable to cast object of type 'Telerik.Web.UI.RadPanelBar' to type 'Telerik.Web.UI.RadControl'.
My Code below...
protected void SetSkins(string colorScheme)
{
List<
Control
> RadControls = new List<
Control
>();
LoopControls(this.Page.Controls, ref RadControls);
foreach (Control c in RadControls)
{
((RadControl)c).Skin = colorScheme;
}
}
public void LoopControls(ControlCollection controls, ref List<
Control
> RadControls)
{
string output = string.Empty;
foreach (Control control in controls)
{
if (!string.IsNullOrEmpty(control.ID) && control.ID.StartsWith("Rad"))
{
RadControls.Add(control);
}
LoopControls(control.Controls, ref RadControls);
}
}
I suppose I could pass the skin name across and set the skin in the LoopControls method, but would still like an answer to my question.