This is a migrated thread and some comments may be shown as answers.

Do RadControls all inherit from RadControl?

3 Answers 86 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 12 Oct 2011, 05:04 PM
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...

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.



3 Answers, 1 is accepted

Sort by
0
Accepted
Stuart Hemming
Top achievements
Rank 2
answered on 12 Oct 2011, 07:43 PM
Karl,

have you considered just putting a RadSkinManager on the page/in your MasterPage?

Doing so would make most of your problems go away with no effort at all.

-- 
Stuart
0
Karl
Top achievements
Rank 1
answered on 18 Oct 2011, 09:59 AM
Never paid any attention to that control, but its exactly the one I was looking for!

Thanks
0
Stuart Hemming
Top achievements
Rank 2
answered on 18 Oct 2011, 11:09 AM
No worries.

Please don;t forget to mark my reply as the Answer to the thread.

-- 
Stuart
Tags
General Discussions
Asked by
Karl
Top achievements
Rank 1
Answers by
Stuart Hemming
Top achievements
Rank 2
Karl
Top achievements
Rank 1
Share this question
or