You are here:   Home
  |  Login
DotNetNuke Core Team
Microsoft MVP
 Bookmark this article!
delicious.com delicious.com
digg digg
technorati technorati
reddit reddit
stumbleupon stumbleupon
facebook facebook
google bookmarks google bookmarks
yahoo bookmarks yahoo bookmarks
slashdot slashdot
live live
twitter twitter
DotNetKicks DotNetKicks

Tags

  1. 1 items are tagged with Admin settings
  2. 1 items are tagged with AJAX Extensions
  3. 1 items are tagged with ASP.NET
  4. 2 items are tagged with BBeyond
  5. 1 items are tagged with Caching
  6. 1 items are tagged with Cambrian
  7. 1 items are tagged with CBO
  8. 2 items are tagged with Codeplex
  9. 1 items are tagged with debugging
  10. 1 items are tagged with DotNetNuke
  11. 2 items are tagged with DotNetNuke 5
  12. 1 items are tagged with Email
  13. 1 items are tagged with email validation
  14. 1 items are tagged with GMail
  15. 1 items are tagged with Google
  16. 1 items are tagged with Google Apps
  17. 1 items are tagged with IBaseEntity
  18. 2 items are tagged with IdentitySwitcher
  19. 1 items are tagged with IHydratable
  20. 1 items are tagged with Inline Skin Object
  21. 2 items are tagged with Installation
  22. 1 items are tagged with Installer
  23. 1 items are tagged with intellisense
  24. 1 items are tagged with IPropertyAccess
  25. 1 items are tagged with Language
  26. 1 items are tagged with Manifest
  27. 1 items are tagged with moving
  28. 1 items are tagged with OpenForce
  29. 1 items are tagged with Permissions
  30. 1 items are tagged with Profile Properties
  31. 1 items are tagged with PropertyEditorControl
  32. 1 items are tagged with recent projects
  33. 1 items are tagged with regex
  34. 1 items are tagged with Sample Module
  35. 1 items are tagged with Search Results
  36. 2 items are tagged with Skin Object
  37. 1 items are tagged with Skinning
  38. 6 items are tagged with SQL
  39. 1 items are tagged with SQL Server
  40. 1 items are tagged with SQL Server 2008
  41. 1 items are tagged with Table Functions
  42. 2 items are tagged with TellCo
  43. 1 items are tagged with TokenReplace
  44. 2 items are tagged with Too Good to be True
  45. 1 items are tagged with Twitter
  46. 2 items are tagged with UPC
  47. 2 items are tagged with Upgrading
  48. 1 items are tagged with Users
  49. 2 items are tagged with visual studio
  50. 1 items are tagged with Visual Studio 2008

My Twitter Feed...

Thu, 29 Jul 2010 16:45:45 +0200

erikvb: Gettin unhealthy food. Yummy!

Thu, 29 Jul 2010 07:06:10 +0200

erikvb: RT @mashable: Google Makes Custom Web Typography Ridiculously Easy - http://ow.ly/2i8DG

Wed, 28 Jul 2010 05:05:48 +0200

erikvb: @Alyssa_Milano cool, you have a clone AND you are followed by @wilw . I can only dream of achieving the same...

Tue, 27 Jul 2010 22:20:49 +0200

erikvb: http://bit.ly/bwCZdB (Popularity is Everything: A new approach to protecting passwords from statistical-guessing attacks)

Tue, 27 Jul 2010 16:51:58 +0200

erikvb: RT @Telerik: Win an iPad or Telerik Ultimate licenses. Contest details at http://bit.ly/99ep9O [please RT]

Tue, 27 Jul 2010 10:06:20 +0200

erikvb: RT @TimoBreumelhof: Small bugfix for Style Helper #DNN #skin object posted: http://dnnskinextensions.codeplex.com/releases/view/47234

Mon, 26 Jul 2010 18:39:00 +0200

erikvb: @jbrinkman have fun playing with it :)

Mon, 26 Jul 2010 18:34:22 +0200

erikvb: @schotman als het maar droog blijft

Mon, 26 Jul 2010 17:51:38 +0200

erikvb: RT @christoc: RT @DNNCorp Get new insights from #DotNetNuke CEO Navin Nagiah at CMS Critic: http://bit.ly/aqkKwm

Sun, 25 Jul 2010 20:35:09 +0200

erikvb: RT @Heuserkampf: This will be interesting: Facebook lets publishers contact “likers”: http://bit.ly/9orOQN

Creating a DotNetNuke inline skinobject

Last Updated 10/26/2008
By: Erik van Ballegoij

Last week I was asked to come up with a way to use the Page Icon in DotNetNuke as a source for a multi lingual enabled image on a page. Although this could have been done by creating a skinobject, I decided to pull this one off by creating an "inline" skinobject.. by lack of a better term.

Before we start, there are a few things we need to keep in mind:

  • because the page icon is selected through the DNN interface, we need one location that is used as default location, without locale
  • DNN Admin pages use page icons, so we need to exclude those (as they are not located in the portal root)

First we start with adding a server side script block, with an asp.net PageLoad eventhandler, to our skin. This is done in the .ascx file of the skin, location in the file does not matter. Like this:

   1:  <script runat="server">
   2:      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   3:      End Sub
   4:  </script>

 

next, we will use a new literal control in the skin to add the code for our image to, like this:

 

   1:  <asp:Literal ID="litMyImage" runat="server" />

 

The code in page_load will look like this. Don't worry, i will explain

 

   1:  <script runat="server">
   2:      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   3:          If (Not String.IsNullOrEmpty(PortalSettings.ActiveTab.IconFile)) Then
   4:              If Not PortalSettings.ActiveTab.IsAdminTab And Not PortalSettings.ActiveTab.IsSuperTab Then              
   5:                  Dim Locale As String = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName
   6:                  Dim myImageFile As String = ""
   7:                  If Locale = "nl" Then
   8:                      myImageFile = PortalSettings.ActiveTab.IconFile
   9:                  Else
  10:                      Dim myFile As String = PortalSettings.ActiveTab.IconFile.Substring(PortalSettings.ActiveTab.IconFile.LastIndexOf("/") + 1)
  11:                      Dim myFolder As String = ""
  12:                      If PortalSettings.ActiveTab.IconFile.LastIndexOf("/") > 0 Then
  13:                          myFolder = PortalSettings.ActiveTab.IconFile.Substring(0, PortalSettings.ActiveTab.IconFile.LastIndexOf("/"))
  14:                          myImageFile = String.Format("{0}/{1}/{2}", myFolder, Locale, myFile)
  15:                      Else
  16:                          myImageFile = String.Format("{0}/{1}", Locale, myFile)
  17:                          
  18:                      End If
  19:                  End If
  20:                  litMyImage.Text = String.Format("<img alt=""{0}"" style=""width:140px"" src=""{1}{2}"" />", PortalSettings.ActiveTab.Title, PortalSettings.HomeDirectory, myImageFile)
  21:              End If
  22:          Else
  23:              litMyImage.Visible = False
  24:          End If
  25:      End Sub
  26:  </script>

 

First we start off by checking for the existence of the iconfile:

 

   3:          If (Not String.IsNullOrEmpty(PortalSettings.ActiveTab.IconFile)) Then

 

Next we check whether the page is an admin tab:

 

   4:              If Not PortalSettings.ActiveTab.IsAdminTab And Not PortalSettings.ActiveTab.IsSuperTab Then              

 

Next, we get the 2-letter ISO code for the current culture:

 

   5:                  Dim Locale As String = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName

 

Next, for the default locale (in this example the default is nl-NL), we use the iconfile as available in DotNetNuke:

 

   7:                  If Locale = "nl" Then
   8:                      myImageFile = PortalSettings.ActiveTab.IconFile

 

For all other locales, we need to do some calculating with the path information. What I'd like to do is to use this for the default locale: [portalroot]/[somepath]/iconfile.ext, and this for all other locales: [portalroot]/[somepath]/[2-letterisocode]/iconfile.ext. We need to do some cutting and pasting in the original path that DNN reports for the icon file:

 

  10:                      Dim myFile As String = PortalSettings.ActiveTab.IconFile.Substring(PortalSettings.ActiveTab.IconFile.LastIndexOf("/") + 1)
  11:                      Dim myFolder As String = ""
  12:                      If PortalSettings.ActiveTab.IconFile.LastIndexOf("/") > 0 Then
  13:                          myFolder = PortalSettings.ActiveTab.IconFile.Substring(0, PortalSettings.ActiveTab.IconFile.LastIndexOf("/"))
  14:                          myImageFile = String.Format("{0}/{1}/{2}", myFolder, Locale, myFile)
  15:                      Else
  16:                          myImageFile = String.Format("{0}/{1}", Locale, myFile)
  17:                          
  18:                      End If

 

Finally, we assign the value of the literal control with our image tag:

 

  20:                  litMyImage.Text = String.Format("<img alt=""{0}"" style=""width:140px"" src=""{1}{2}"" />", PortalSettings.ActiveTab.Title, PortalSettings.HomeDirectory, myImageFile)

I would agree that this is some work, however, we now have the option of a multilanguage page icon in our page. Of course a skinobject would also have worked, but the nice thing about this solution is that it will just work in this particular skin. Also, you can just package the skin and install it on a different installation and it will still work. In a sense you now have the option to include a skinobject with your skin.

Of course... you will be able to do that with DNN 5.0 anyway, but in a way this brings a great DNN 5.0 feature to DNN 4.x

The code in this blog was tested on DNN 4.9.0

Rate this:
Recent Comments

I notice your example plugged in .net code directly to the page. Is it possible to create an aspx/ascx page and include it in the skin and upload a vb/cs codebehind up with your skin so that items that are programatically designed(eg a custom menu) can be embedded to your skin?

Posted By: Bart Chavez on 10/18/2008
Yes thats quite possible. Remember that a skinobject is just a user control, so you can include your own usercontrol (ascx file) in your skin package and reference that from the skin. I have not tested that, but you probably won't be able to use separate code behind files as those file types are not allowed by DNN. I will do an example of how that works in one of my next blogs.
Posted By: Erik van Ballegoij on 10/19/2008
Very cool walk-through. Thanks!
Posted By: Will Strohl on 12/09/2008
Upon further inspection, dnn appends every server control with an explicit short name in Default.aspx. Therefore, if my control had of "myControl" it would be changed to something like "dnn_myControl"... How were you able to get around this? Thanks.
Posted By: David S on 10/29/2009
I have tried adding a literal to my skin and adding a page_load event to change the text of that literal, but it does not work. Am I missing something? Using DNN 5.
Posted By: David S on 10/29/2009

Powered By

DotNetNuke Powered! This site is proudly powered by DotNetNuke.

 

(Advertisements)

My other blogs

Thu, 21 May 2009 18:41:00 +0200

Fri, 01 May 2009 14:57:00 +0200

Wed, 29 Apr 2009 16:11:00 +0200

Mon, 27 Apr 2009 20:33:05 +0200

Wed, 21 Jan 2009 20:13:00 +0100

Mon, 05 Jan 2009 23:00:00 +0100

Fri, 05 Dec 2008 16:45:08 +0100

Sun, 05 Oct 2008 22:23:00 +0200

Wed, 17 Sep 2008 14:07:00 +0200

Sun, 24 Aug 2008 21:23:00 +0200