Selecting a skin from a Page_Load

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
10/10/2012 5:17:09 AM
Gravatar
Total Posts 40

Selecting a skin from a Page_Load

Hi there,

I have developed modules on top of MojoPortal but i want them to have a Skin different from my main site. How can i select the skin from my codeBehind Page_Load or OnInit perhaps? I've seen this is possible within mojo if it was a page, which it is not :(

EDIT: Forgot to mention my module is a NonCmsBasePage.

Best regards,
João

10/10/2012 9:20:56 AM
Gravatar
Total Posts 18439

Re: Selecting a skin from a Page_Load

If you have specified a skin in Page Settings for the CMS page that has your feature, and you are passing the pageid param to your supporting page, just do this:

protected override void OnPreInit(EventArgs e)
{
AllowSkinOverride = true;
base.OnPreInit(e);
}

that tells the base page that the page specific skin should be allowed.

Hope that helps,

Joe

10/11/2012 9:35:34 AM
Gravatar
Total Posts 40

Re: Selecting a skin from a Page_Load

Thanks for the answer.

That code forced the layout.Master to be loaded but the css was not.
Am I missing something?
Isn't there a SetSkin("xpto") somewhere? :)

Best regards,
João

10/11/2012 3:27:00 PM
Gravatar
Total Posts 192

Re: Selecting a skin from a Page_Load

I once used this:

//    //((mojoBasePage)Page).AllowSkinOverride = true;        this is not needed.
//    ((mojoBasePage)Page).MasterPageFile = SiteUtils.GetMasterPage(this, "skin", siteSettings, true);
//    CurrentPage.Skin = "skin";
//    ((mojoBasePage)Page).StyleCombiner.AllowPageOverride = true;

 

(but it's not used now in the project, I was using physical pages, so specifying a master page for that page in page asp.net header was enough, and the page was a simple asp.net web page. I think the code above works.)

10/12/2012 4:22:20 AM
Gravatar
Total Posts 40

Re: Selecting a skin from a Page_Load

Hi paiman,

That is what i want to do. Force a skin from the code behind. But your code does not change the skin.

While debugging:

MasterPageFile = SiteUtils.GetMasterPage(this, "EticadataApplication", siteSettings, true);

returns "/App_MasterPages/layout.Master";

And the main skin is rendered.

I want the user to be able to change the main skin for the site, but my selected pages all need to use the same skin and layout.

Any ideas?

EDIT: I forced

MasterPageFile = "~/Data/Sites/1/skins/Intranet/layout.Master"

and rendered the main skin :/

Thanks in advance,
Best regards,
João

10/12/2012 8:26:09 AM
Gravatar
Total Posts 18439

Re: Selecting a skin from a Page_Load

Maybe you are not really implementing a feature like the existing features are implemented. Existing features support page skins exactly as I have told you.

For example:

  1. In Site Settings check the box to allow per page skins
  2. Create a page and put an instance of Forums on the page
  3. In Page Settings for the page that has the forums select a different skin
  4. The skin will be used on the page and in the supporting pages of the forum ie ForumView.aspx and Thread.aspx
  5. The reason it works is because it uses the same code I showed you in those pages

protected override void OnPreInit(EventArgs e)
{
AllowSkinOverride = true;
base.OnPreInit(e);
}

For it to work the ModuleControl (ForumModule.ascx) for the forums must pass the pageid parameter in its links to ForumView.aspx and ForumsView.aspx passes the pageid param to Thread.aspx

You can study example code for existing features and step through it and see that it works.

Hope that helps,

Joe

10/15/2012 4:02:07 AM
Gravatar
Total Posts 40

Re: Selecting a skin from a Page_Load

Thank you for your answer Joe.

I have a typical instalation of MojoPortal.

On the frontend, i have a special menu when logged in for different intranet modules.

For instance, i have the Human Resources module so i have a link for ~/HumanResources/HumanResources.aspx

that page is:

public partial class HumanResources : NonCmsBasePage
{

protectedoverridevoid OnPreInit(EventArgs e)
{

//AllowSkinOverride = true;
MasterPageFile=SiteUtils.GetMasterPage(this, "Intranet", siteSettings, true);
//MasterPageFile = "~/Data/Sites/1/skins/Intranet/layout.Master";
CurrentPage.Skin ="Intranet";
StyleCombiner.AllowPageOverride =true;
base.OnPreInit(e);

}

....

And as i have told you, although i have a link for the module using a mp_Pages entry, i don't think the information from mp_Pages is passed to the module. Should i be creating my module differently?

I have inherited this project so this is how it was done, but i can (and should) change it since i am starting to work with it if you believe it is not properly implemented.

Thank you for your time.

Best regards,
João

10/15/2012 10:30:44 AM
Gravatar
Total Posts 18439

Re: Selecting a skin from a Page_Load

You are working against the grain of the system by not building features the recommended way.

Instead of HumanResources.aspx why not make HumanResourcesModule.ascx as a feature that plugs into a cms page, this is how the entry point of a feature should be implemented, then if you need additional supporting pages for the feature you link from the .ascx to .aspx page and pass the pageid and module id

The problem with the way you are doing it is that since no page id is passed in no page specifc skin can be applied and without a pageid is the same as if passing in the home page page id, that is what makes it the default page.

You could solve it from your own code without follwoing this recommendation but you make more work for yourself.

You will have to so it in OnPreInit but after OnPreInit completes in mojoBasePage so that you change it after mojoBasePage

protected override void OnPreInit(EventArgs e)
{
// let mojoBasePage do its thing
base.OnPreInit(e);

// write your own code here to set it as you wish but you'll have to figure out how to do that from code in mojoBasePage
}

I think it is better work with the grain of the wood not against the grain of the wood by implementing it in the recommended way as an .ascx you will have less work to do, by going against the grain you have to do more work.

Hope that helps,

Joe

10/15/2012 10:35:45 AM
Gravatar
Total Posts 40

Re: Selecting a skin from a Page_Load

Thanks for your answer.

Like i said, I inherited 5 modules programmed this way and now i am trying to figure out how this works.

I'll try and follow your tips and get back to you.

Best regards

João

10/15/2012 3:37:06 PM
Gravatar
Total Posts 18439

Re: Selecting a skin from a Page_Load

I think it would not be so difficult to copy the code and logic from a .aspx page into a .ascx user control that can then be loaded on a cms page like any other feature, but its up to you of course.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.