John Mitchell Administrator
 Veteran Member
 Posts:4384

 | | 13 Apr 2007 11:14 AM |
| Here is a way to dynamically load a skin based on the portal alias used to access the site.
All you need is the following code pasted into a file by itself. Then you can name it something like "PortalAliasSwitcher.ascx" and put it in a skin folder along with the skins that you want it to load based on the Urls. Then go in and assign this file to the page, site, or host settings like you would normally do an individual skin. <%@ Control language="vb" AutoEventWireup="false" Explicit="True" %><asp:placeholderid="SkinPlaceholder"runat="server"/><scriptrunat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'** Skincovered.com Portal Alias based skin switcher
'** Switches the skin depending on the Url used to access the site
'** Select this skin (PortalAliasSwitcher) as would any other skin in DotNetNuke
'** The code below will load a skin from the same folder depending on the Url
Dim skin As String = ""
Select CType(HttpContext.Current.Items( "PortalSettings"),PortalSettings).PortalAlias.HTTPAlias.ToLower()
Case "hr.mydomain.com":
skin = "HumanResources.ascx"
Case "it.mydomain.com":
skin = "InformationServices.ascx"
Case Else:
'this skin will be loaded if no matches were made to the portal aliases above
skin = "default.ascx"
End Select
'this line loads the actual skin.
SkinPlaceholder.Controls.Add(LoadControl(skin))
End Sub <script>
|
| | |
|
dschaening
 New Member
 Posts:15
 | | 28 Aug 2007 02:03 PM |
| This is a great feature...Any Idea on how I could handle this with a wildcard? say *.mydomain.com is skin A and *.myotherdomain is skin B? |
| | |
|
John Mitchell Administrator
 Veteran Member
 Posts:4384

 | | 11 Sep 2007 10:38 PM |
| I'm sorry I missed this question earlier.
For getting all the hosts on one domain you could just see if the domain name is in the Url.
Something like:
If Request.Url.Host.IndexOf("mydomain.com") > -1 Then
skin = "mydomain.ascx"
ElseIf Request.Url.Host.IndexOf("myotherdomain.com") > -1 Then
skin = "myotherdomain.ascx"
End If |
| | |
|
psidrum
 New Member
 Posts:3
 | | 21 Sep 2007 09:42 PM |
| Hello, i tried this but i get this error
An error has occurred. DotNetNuke.Services.Exceptions.PageLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DotNetNuke.UI.Skins.Skin.Page_Init(Object sender, EventArgs e) at System.Web.UI.Control.OnInit(EventArgs e) at System.Web.UI.UserControl.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.AddedControl(Control control, Int32 index) at System.Web.UI.ControlCollection.Add(Control child) at ASP.portals_14_skins_7893_sp002_blue_portalaliasswitcher_ascx.Page_Load(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---
Do you know whats wrong with it? Im using DNN 4.5.1
|
| | |
|
psidrum
 New Member
 Posts:3
 | | 21 Sep 2007 10:07 PM |
| THe code seems to work but it gives me an error when i am logged in as Admin or Host...But if i log out the skin seems to work, but login, the skin does not work. How can i fix this problem? |
| | |
|
John Mitchell Administrator
 Veteran Member
 Posts:4384

 | | 24 Sep 2007 04:35 PM |
| It may be that you need to add a ControlPanel container to your skin. In the actual skin(s) that you are switching to, make sure that there is a line like this: <divid="ControlPanel"runat="server"></div> Also, if you want to link to a specific CSS file for the skin that you are switching to the easiest way is to put the css link directly in the skin like this: <linkrel="stylesheet"type="text/css"href='<%= Page.ResolveUrl("black_full.css") %>'/> |
| | |
|
nina
 New Member
 Posts:34
 | | 28 Oct 2007 06:33 AM |
| Another challenge for you John - I've tried to do something one way and then another but not able to get the exact results- I then thought a skin by role might be the answer... What I have is a site where tehre are three products being offered for sale (there might be more but you'll get the idea... ) I tried to add images with link based on role but I wanted to be upselling to these people, and not show the products if they have already bought it. EG.. I'm a registered user but bought nothing - so the idea is to show products 1, 2 & 3 But if I've bought product 1, I'd like to be able to upsell 2 & 3, but not show product 1 since they have bought it. If I've bought product 2, I'd like to upsell to product 3, but not show products 1 & 2, since they have bought them, and of course if they have bought product 3, dont' want to show any. I tried various methods of trying to hide one thing from another but coudn't work out the roles, so thought that the skin based on role would be ideal, as I'd just have these items displayed in the montage, but I then tried to jiggle the code around, and of course - was hugely... BAD at it.. So, is my thought going down the path? I thought the skin switcher features were so good, I could work with it. Thanks Nina |
| | |
|
nina
 New Member
 Posts:34
 | | 28 Oct 2007 06:36 AM |
| OH and I forgot to mention - that each of these skins has a role attached - as when you purchase the product you get assigned a role - I realise that is an important feature or otherwise how would you get it to work in the first place. Nina |
| | |
|
John Mitchell Administrator
 Veteran Member
 Posts:4384

 | |
arifshah
 New Member
 Posts:1
 | | 14 Nov 2007 09:52 AM |
| Hi John,
I am looking for options to apply a Low Graphics version on my site. From what I understand, it could be achieved by switching skin to NoSkin.ascx user control. But I would need to do that by clicking on my default page skin to switch to Low Graphics and switch back to the skin applied on the page by clicking on another link on the Low Graphics skin.
Essentially its skin switching by link clicks rather than based on portal alias or role.
Any advice would be great help.
Regards Arif Shah |
| | |
|
John Mitchell Administrator
 Veteran Member
 Posts:4384

 | | 14 Nov 2007 11:34 AM |
| Hi Arif, You can switch skins using the querystring by passing it with the SkinSrc parameter. If you go into Site Settings or Page Settings and click on Preview button for a skin then you can see the format which is basically like this [G]/Skins/Skincovered_Feb/Login Which means use a host level skin [G] in the /Skins/Skincovered_Feb folder called Login.ascx If the Skin was at the portal level it would be [L] instead of [G] http://www.snapsis.com?tabid=1&SkinSrc=%5bL%5dSkins%2fSkincovered_Feb%2flogin |
| | |
|
mcselasvegas
 New Member
 Posts:1
 | | 28 Feb 2009 01:45 PM |
| Hi John,
I am using dnn 4.9.2 and get the following error if I try to use the Skin Switcher...
Could Not Load Skin: /Portals/0/Skins/SkinSwitch/SkinSwitcher.ascx Error: Unable to cast object of type 'ASP.portals_0_skins_skinswitch_skinswitcher_ascx' to type 'DotNetNuke.UI.Skins.Skin'
Does your code not work with this version? The Skin engine might have been rewritten? Do you have a solution for later dnn versions?
Thank you, Oliver |
| | |
|
John Mitchell Administrator
 Veteran Member
 Posts:4384

 | | 02 Mar 2009 10:36 PM |
| From the error, it does appear that they have changed the Skin engine to require a skin to be inherited from DotNetNuke.UI.Skins.Skin. Try adding this code to the top of the switcher: <%@ Control language="vb" AutoEventWireup="false"
Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %> |
| | |
|
jerops
 New Member
 Posts:54
 | | 26 May 2009 05:35 PM |
| Hi John, I'm trying to use your roleswitcher.aspx code on a minimalist 2.0 skin and it doesn't appear to be picking up the CSS file. Each Minimalist ascx skin file has an associated css file named the same as the ascx file in order for it work...I see above in the forum you have talked about linking the CSS skin . How can I incorporate that into your RoleSwitcher.aspx code? Can I put that right after the skin = "MySkin.ascx" line?
Thanks for help, I really appreciate it. Jerry |
| | |
|
gbrown
 New Member
 Posts:1
 | | 16 Jul 2009 04:12 PM |
| John-
Thanks for these!! They will come in handy for many applications. I do have a different use case that may be too difficult or need to be done some other way. I need to look for a querystring variable in the url, look up the skin choice stored with that variable in a table, and then change the skin to the stored skin choice. It would also need a default skin if no skin choice was found. I can handle building the table and getting the data into the table - but A) Can I use a similar ascx file method as you have done here and B) What might the code look like to do this?
If you have the time to reply to this that would be great, if not I understand.
Greg Brown |
| | |
|
mdata
 New Member
 Posts:3
 | | 05 Aug 2009 03:35 AM |
| Does this script need any changes for DNN5? I've applied the Inherits= attribute as suggested above, but am now hitting another error (excuse formatting):
DotNetNuke.Services.Exceptions.PageLoadException: The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases. ---> System.Web.HttpException: The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases. at System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) at DotNetNuke.UI.Skins.Skin.InjectControlPanel() at DotNetNuke.UI.Skins.Skin.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.AddedControl(Control control, Int32 index) at ASP.portals__default_skins_myskin_nomenu_switch_ascx.Page_Load(Object sender, EventArgs e)
I also added a ControlPanel div, seeing the reference to that in the backtrace, but the error still appears
Google and my limited ASP knowledge haven't helped to figure out what's going on ... any pointers? |
| | |
|
snagen
 New Member
 Posts:1
 | | 05 Aug 2009 01:48 PM |
| I'm getting a similar error in DNN 5.1 too. It worked great in the previous version of DNN. This is the exception I get Method: DotNetNuke.UI.Containers.ActionButtonList.get_ModuleActions StackTrace: Message: DotNetNuke.Services.Exceptions.PageLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DotNetNuke.UI.Containers.ActionButtonList.get_ModuleActions() at DotNetNuke.UI.Containers.ActionButtonList.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --- |
| | |
|
mdata
 New Member
 Posts:3
 | | 07 Aug 2009 03:27 AM |
| snagen, I've done some more investigation on my end, including deploying on DNN4.9 -- I had the same error you mention until I took the following steps:
Add [ div id="ContentPane" runat="server" / ] to the target skin.
Made sure the skinswitcher.ascx had a corresponding skinswitcher.doctype.ascx and an empty skinswitcher.css (not sure if these are neccessary).
I also changed the switcher skin to include a dummy ControlPanel and ContentPane, and added code to select the CSS based on the selected skin. The alterations to the original skinswitcher.aspx are as at http://pastebin.com/f536192bc
With these changes it works like a charm on DNN4.9, but I still get the same error as above (The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases) on DNN5.1. I hope someone can help track this down!
EDIT: how do you post HTML to this forum? Even HTML-escaping the content twice my script block got removed! |
| | |
|
mdata
 New Member
 Posts:3
 | | 09 Aug 2009 11:26 PM |
| Apparently in DNN5 skins are handled in such a way that this can no longer be done in Page_Load -- it's possible that the code could be made to fire at another point in the request cycle, but I had no success with this. A reasonable compromise we have settled on is to use a single skin with the above code embedded in it, modified to only update the CSS link and to store the skin name in a global variable for use on HTML elements where it is required. It's a bit more code in the skin than I'd like, but the approach seems to be robust. |
| | |
|
reto.cossalter
 New Member
 Posts:2
 | | 12 Aug 2009 03:09 AM |
| Thanks John for the code. Just what I needed. |
| | |
|