Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Want to Change Page Skin ProgrammaticallyWant to Change Page Skin Programmatically
Previous
 
Next
New Post
11/6/2008 9:36 AM
 

I am developing a module which will allow the user to choose and apply the different skin for the different pages. I am having some problem in doing so.

Following is the partial code but is fully understandable (yes this has been coded in the Page_Init of the Module's View Control)

            PortalSettings.ActiveTab.SkinSrc = SkinController.formatSkinSrc(_SelectedSkin, PortalSettings);
            ctlSkin = LoadSkin(PortalSettings.ActiveTab.SkinSrc);

            ctlSkin.ID = "dnn";

            // ADD CSS LINKS
            ManageStyleSheets(false);

            // ADD SKIN TO PAGE
            PlaceHolder SkinPlaceHolder;
            SkinPlaceHolder = (PlaceHolder)Page.FindControl("SkinPlaceHolder");
            if (SkinPlaceHolder != null)
            {
                SkinPlaceHolder.Controls.RemoveAt(0); // to remove the previous control sets
                SkinPlaceHolder.Controls.Add(ctlSkin); // to apply the new skin
            }

 

but i am getting the 'Object Instance' error message at the last line "SkinPlaceHolder.Controls.Add(ctlSkin)" and nothing is applied.

Also When i am using the Id for ctlSkin.Id other than "dnn" and commenting the line "SkinPlaceHolder.Controls.RemoveAt(0);" it actually inserts the New Skin within the Old Skin which is not accepteable.

Please help me in correcting the issue....Please let me know if you want more information on what I did ...but to my information i have given the relevant information.

Also , if you know the other solution but programmatically then please suggest that too... Thank you

 
New Post
11/7/2008 1:31 AM
 

I have a similar, but different requirement.

I need a portal to dynamically load a skin based on a user selection from a list of available skins. I read an interesting article which suggested creating a "proxyskin.ascx" file and use that as the portal default skin. Basically the Skin Proxy determines which user selected skin to use and then attempts to load a user control (ie a skin) of that name as follows:-

SkinProxy.ascx

<%@ Control language="vb" CodeBehind="~/admin/Skins/skin.vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %>
<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim UserSkin As String = "someuserskinchoice.ascx"
            Controls.Add(LoadControl(UserSkin))
        Catch ex As Exception
            Controls.Add(LoadControl("Default.ascx"))
        End Try
    End Sub
</script>

In this pseudo code, some logic is executed to determine the name of the user selected skin. Then an attempt is made to load a control whose name matches that skin name. If unsuccessful, a control named Default.ascx is loaded. 

This sounds like it should work, but I get the following error:-

AssemblyVersion: 04.09.00
PortalID: 7
PortalName: Pro-Ma Retail Store
UserID: 2
UserName: admin
ActiveTabID: 1375
ActiveTabName: Custom1
RawURL: /Default.aspx?tabid=1375&error=Object+reference+not+set+to+an+instance+of+an+object.&content=0
AbsoluteURL: /Default.aspx
AbsoluteURLReferrer:
UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)
DefaultDataProvider: DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider
ExceptionGUID: 7385000e-1e1d-4416-8180-135ddcb2cfbf
InnerException: Object reference not set to an instance of an object.
FileName:
FileLineNumber: 0
FileColumnNumber: 0
Method: DotNetNuke.UI.Skins.Skin.Page_Init
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.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__default_skins_nifosspwine_skinproxy_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 ---
Source:
Server Name: STAGING

Anyone know what's wrong with this????

 
New Post
11/7/2008 6:29 AM
 

Well Chris,

I dont know the exact solution of your problem, but what i am looking , you should always add the run-time controls in the Page_Init event, this will not work if you try this in Page_Load.

Please correct me if I am wrong somewhere.

 

 
New Post
11/10/2008 10:43 PM
 

Thanks for your reply Sachin...

I have placed the code in the Page_Init event as suggested, but with the same result.... :(

Some one out there must know how to do this - any help would be appreciated.

 
New Post
11/11/2008 12:35 AM
 

Basically you need to loop the current object parent to find the correct SkinPlaceHolder,

This is a sample code, feel free to modify. I havent test the code yet.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim ps As PlaceHolder = FindSkinHolder()
End Sub

Protected Function FindSkinHolder() As PlaceHolder
    Dim found As Boolean = False
    Dim ctl As Control = Me.Parent
    While Not found
        If ctl <> Nothing Then
            For Each c As Control In ctl.Controls
                If c.ClientID = "SkinPlaceHolder" Then
                    Return DirectCast(c, PlaceHolder)
                End If
            Next
                        'Looping for the next parent
            ctl = ctl.Parent
        Else
            'Exit the loop if not found the skinHolder
            Exit While
        End If
    End While
    Return Nothing
End Function

To make it load faster, once you have found the placeholder, you may set them into a session, so you can avoid to loop the parent again.

Hope this help everyone =D

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Want to Change Page Skin ProgrammaticallyWant to Change Page Skin Programmatically


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out