Do RadControls all inherit from RadControl?

4 posts, 1 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Sep 2010

    Posted 12 Oct 2011 Link to this post

    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.



  2. Answer
    Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 12 Oct 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Karl
    Karl avatar
    172 posts
    Member since:
    Sep 2010

    Posted 18 Oct 2011 Link to this post

    Never paid any attention to that control, but its exactly the one I was looking for!

    Thanks
  5. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 18 Oct 2011 Link to this post

    No worries.

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

    -- 
    Stuart
Back to Top