Dec 18, 2008

Telerik RadSkinManager doesn't persist the Skin.


If you programatically change the Telerik RadSkinManager Skin property it won't get persisted in the key you added.
This is because probably in telerik asumed if there is no skin chooser the skins won't change and will be loaded from the markup. It is not a bad decision.
However, you may find yourself in need to programatically change the skin and want it persisted.
To do the things tidy I did a small code to persist the skin where it should be persisted.
Here is the code:
        
switch (rsMgr.PersistenceMode)
        {
          
case RadSkinManagerPersistenceMode.Cookie:
            
// Create a cookie to persist the skin selection for the session only:
             HttpCookie cookieSkin = new HttpCookie(rsMgr.PersistenceKey, rsMgr.Skin);
             Response.Cookies.Add(cookieSkin);
            
break;
          
case RadSkinManagerPersistenceMode.Session:
            
// Create a session variable with the same name:
             Session[rsMgr.PersistenceKey] = rsMgr.Skin;
            
break;
          
case RadSkinManagerPersistenceMode.ViewState:
            
// View state variable:
             ViewState[rsMgr.PersistenceKey] = rsMgr.Skin;
            
break;
        }

where rsMgr is RadSkinManager.
Now you may paste this code in a method and call this method after you programatically assign skin to the manager. I needed this because I wanted to allow the user to change from some of the skins (not all of them) I couldn't find a way to only hide few skins and display others so I can use the standard functionality of the SkinChooser proerty so I added my own RadCombobox with the skins I want displayed.

Hope this helps someone out there...

No comments: