RSS

Changing MasterPageFile

Thu, Aug 14, 2008

ASP.NET, Code

Snippet-Admin/Default.aspx

I added this code to my admin files to enable me to change masterfilepages on the fly. I tried with global variables and with properties but my masterpagefile would always default back the hardcoded file somehow.

Private Function changeTheme(ByVal strNewThemePath As String) As String
        If File.Exists(Server.MapPath(strNewThemePath)) Then
            Application.Set("theme", strNewThemePath)
            Return String.Format("Theme changed successfully to: ""{0}""", strNewThemePath)
        Else
            Return String.Format("The file: ""{0}"" does not exist. Theme not changed.", strNewThemePath)
        End If
End Function

Snippet-Global.asax

I also added this to the global.asax file since the code above did not specify a default theme.

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        'If no other theme is chosen then load the default
        If Application("theme") Is Nothing Then
            Dim Config As New Config
            Application("theme") = Config.strDefaultTheme
        End If
    End Sub
Share and Enjoy:
  • Facebook
  • Twitter
  • MySpace
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
, ,

Comments are closed.