Hello All
Ive just converted a feature from a site i am upgrading to dnn. which was to have a drop downlist change the text size of the page content.
Ive hacked it together in about half an hour, and although it works, i would like some feedback from people with greater experience than me with DNN, im sure there are better ways to use its features than i have (this is my first module btw)
The user control code is as follows :
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="textsize.ascx.vb" Inherits="DesktopModules_TextSize_textsize" %>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="100%">
<asp:ListItem Value="3">X Large</asp:ListItem>
<asp:ListItem Value="2">Large</asp:ListItem>
<asp:ListItem Selected="True" Value="1">Medium</asp:ListItem>
<asp:ListItem Value="0">Small</asp:ListItem>
</asp:DropDownList>
and the code behind :
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity
Partial Class DesktopModules_TextSize_textsize
Inherits Entities.Modules.PortalModuleBase
'Users changes font size
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
'Set Profile Value
DotNetNuke.Services.Personalization.Personalization.SetProfile(ModuleId.ToString, "textsize", Me.DropDownList1.SelectedIndex)
'Set session value
Session("textsize") = Me.DropDownList1.SelectedIndex
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim iTxtSize As Int32
'Is the user logged in
If UserId > -1 Then
iTxtSize = DotNetNuke.Services.Personalization.Personalization.GetProfile(ModuleId.ToString, "textsize")
Else
'check if the anon user has a value stored in session
If Session("textsize").ToString.Length > 0 Then
iTxtSize = Int32.Parse(Session("textsize"))
Else
'Otherwise set text size to medium, and store in session
iTxtSize = 2
Session("textsize") =iTxtSize
End If
End If
Dim TextSize As New Style()
Select Case iTxtSize
Case 0 'XL
TextSize.Font.Size = FontUnit.Parse("1.4em")
Case 1 'L
TextSize.Font.Size = FontUnit.Parse("1.2em")
Case 2 'M
TextSize.Font.Size = FontUnit.Parse("1em")
Case 3 'S
TextSize.Font.Size = FontUnit.Parse("0.8em")
End Select
'override '.normal' css class's font size
Me.Page.Header.StyleSheet.CreateStyleRule(TextSize, Nothing, ".normal")
'Set the selected index of the DDL
Me.DropDownList1.SelectedIndex = iTxtSize
End Sub
End Class
i created an additional profile property called textsize to allow the uses preferences to be saved for registed users between sessions, and a session based value is used for anon users to maintain there prefs across pages during there session
any comments greatfully taken
chuBb.