The Patapsco Research Group

Current Articles | Archives | Search

Thursday, December 31, 2009
Modified DotNetNuke USER Skin Object
By host @ 10:25 AM :: 810 Views :: BlogEntry
 

Someone asked me how to get the DotNetNuke USER skin object to display the UserName instead of the DisplayName.

This functionality is not part of the USER skin object, so I suggested that it would be be relatively easy to modify the USER to display UserName.  It turns out that it took me all of a half-hour or so to create a modified skin oject with the desired functionality.  Here is how I did it (and writing about it is going to take more time than the actual work!).  This skin object works for DotNetNuke version 5.x.

There were two parts of this project.  First, I had to create the appropriate files.  Then I had to package them so that my new skin object could be installed in DotNetNuke.

USER-A Skin Object

The USER skin object consists of two files found in the Admin/Skins directory:  User.ascx and User.ascx.vb.  I grabbed copies of these files, and renamed them to User-a.ascx and User-a.ascx.vb.  Then, I needed to change the reference to the CodeFile in User-a.ascx.  Finally, I changed the name of the ascx file in the Constants section of User-a.ascx.vb.

The meat of the skin object is contained in User-a.ascx.vb. Basically, what I needed to do is to add an attribute to the skin object that determines whether DisplayName or UserName is displayed.  To do this,  I needed to add a private member to the User class (it's the highlighted line):

#Region "Private Members"

        Private _text As String
        Private _cssClass As String
        Private _url As String
        Private _option As String

#End Region

Next, I added methods to access this member.  I decided that the attribute should be called DisplayOption.  The code looks like this:

        Public Property DisplayOption() As String
            Get
                Return _option
            End Get
            Set(ByVal Value As String)
                _option = Value
            End Set
        End Property

Finally, I have to use the new attribute in the Page_Load Event Handler.  Here is my code (the highlighted lines are my additions):

                    If objUserInfo.UserID <> -1 Then
             If DisplayOption = "UserName" Then
                 cmdRegister.Text = objUserInfo.UserName
             Else
                 cmdRegister.Text = objUserInfo.DisplayName
             End If
                 cmdRegister.ToolTip = Localization.GetString("ToolTip", Localization.GetResourceFile(Me, MyFileName))
          End If

The original USER skin object simply puts the DisplayName into the text of the cmdRegister LinkButton.  My modified USER-A skin object changes this behavior to use UserName if the DisplayOption attribut is set to "UserName."

Packaging

My approach to packaging is to find and example that works and then copy it!  I took a copy of a skin oject from http://dnnskinextensions.codeplex.com/, and edited the dnn file to match my needs.  Then, I zipped the dnn file and my two skin object files so that it could be installed using the DotNetNuke Extensions installer.

Using USER-A

You use the USER-A skin object by adding it to a skin.  You'll need to do two things.

First, register the skin object by adding a line like this to your skin file:

<%@ Register TagPrefix="dnn" TagName="USERA" Src="~/DesktopModules/User-A/User-A.ascx" %>

My dnn file installs the skin object in the DesktopModules/User-A directory.

Then, replace the reference to the USER skin object with a reference to USER-A.  If you are using the ascx file for skinning, then you'll need:

<dnn:USERA runat="server" id="dnnUSER"  CssClass="user" DisplayOption="UserName" />

That's it!

Click here to download my code.

Comments
Copyright (c) 2010 Patapsco Research Group   Login