Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2006, 06:59 PM
rjd rjd is offline
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default BugBase: Adding dynamic themes in Master Page

I would like to allow users to select different themes. I have defined buttons in MasterPage.master, a ImageButton_Command()function in MasterPage.master.vb, a string ProfileTheme in profile property in web.config and several themes in App_Themes directory.

The problem I am having is that the partial class MasterPage
already inherits System.Web.UI.MasterPage which prevents me from inheriting a class that would overrides the OnPreInit event where I can set the Theme property. After setting the Theme property, I would execute a Server.Transfer directive.

Can you help me? Thanks.
 
Old November 7th, 2006, 07:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Instead of inheriting from MasterPage, the Master Page could inherit from your custom class that in turn inherits from MasterPage. E.g.

MasterPage
  YourMasterPageBase
    SomeConcretePage

You can simply replace that class that the master page inherits from in the code behind for the file.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 7th, 2006, 07:26 PM
rjd rjd is offline
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow! What response time!

Imar, I'm a little new at this so here is what I need:
Define MyBasePage.vb in App_Code
Imports System.Web.UI.Page

Public Class MyBasePage
    Inherits System.Web.UI.Page

    Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
        MyBase.OnPreInit(e)
        Dim MyProfile As System.Web.Profile.ProfileBase
        MyProfile = HttpContext.Current.Profile
        Me.Theme = MyProfile.GetPropertyValue("ThemePreference")
    End Sub

End Class
Right?
Next, how do I include this class in MasterPage.master.vb?
 
Old November 8th, 2006, 02:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Almost. Remember you're inheriting from MasterPage, not Page. In fact, Page has nothing to do with this until you reach the point where you start creating pages based on that masterpage:

MasterPageBase.vb in App_Code
Code:
Partial Class MasterPage
  Inherits MasterPageBase
End Class
(Not that I don't "Import" System.Web.UI.Page because a) System.Web.UI is available already and b) System.Web.UI.Page is not a namespace but a class)

Next, you can change your Masterpage from this:
Code:
Partial Class MasterPage
  Inherits System.Web.UI.MasterPage
End Class
to this
Code:
Partial Class MasterPage
  Inherits MasterPageBase
End Class
With this code, your MasterPage inherits from your cusom MasterPageBase class, and no longer from the default MasterPage class.

You can do the same with content pages; but this time, your PageBase class inherits from Page, and your actual pages inherit from PageBase.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 13th, 2006, 08:27 PM
rjd rjd is offline
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe that I have successfully implemented theming with the following code:
In Web.Config:
    <profile>
      <properties>
        <add name="PreferredTheme" type="string" defaultValue="Blue"/>
      </properties>
    </profile>
Create a new file: /App_Code/BasePage.vb
  Imports System.Web.UI.Page

  Public Class BasePage
    Inherits System.Web.UI.Page

    Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
        MyBase.OnPreInit(e)
        Dim MyProfile As System.Web.Profile.ProfileBase
        MyProfile = HttpContext.Current.Profile
        Me.Theme = MyProfile.GetPropertyValue("PreferredTheme")
    End Sub
  End Class
In MasterPage.master I created several imagebuttons representing different theme colors.
In MasterPage.master.vb:
  Sub ImageButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        If (e.CommandName = "setTheme") Then
            Profile.SetPropertyValue("PreferredTheme", e.CommandArgument)
            Response.Redirect(Request.Path)
        End If
    End Sub
Change the Inherits directive of all pages that you want to access these imagebuttons to
Inherits BasePage

The problem I am still having is that the pages are cached. If you visit a page with one theme and then change the theme and then revisit a page, that revisited page may be cached and will show up using the previous theme. I know that I can add the directive:
<%@ OutputCache Location="None" %>
to make sure that the page is not cached.
Is there a better solution? Most users don't switch themes that often.
 
Old November 14th, 2006, 11:17 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I am a bit surprised the pages are cached. Since there's so much dynamic data in the system, you probably don't want to cache page output at all. Instead, the code uses the cache programmatically to insert stuff that doesn't change too often.

Did you change anything so the system is caching?

Imar
 
Old November 14th, 2006, 03:08 PM
rjd rjd is offline
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,
To the best of my knowledge, I haven't changed anything to induce page caching. I have kept sql caching defined in web.config. Maybe sql caching has a side-effect of saving old pages. Does that sound right?

When this themeing problem occurs, I just hit the 'Reload current page' button image on the browser and the page shows proper themeing.
Bob
 
Old November 18th, 2006, 12:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No it shouldn't. The data cached from SQL Server is cached in memory, not in pages.

This sounds more like a browser caching issue. When you debug the page and set a break-point on Page_Load, does that breakpoint get hit when you request the page?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 21st, 2006, 02:17 PM
rjd rjd is offline
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,
You are correct, it IS a browser caching issue, when I set a breakpoint
in the Page_Load, it doesn't reach it and the generated page does not reflect the new theme.

Also, you have to be selective where you place the directive
<%@ OutputCache Location="None" %>.

The page that contain DataGrids can not have the directive because when you view a particular record and press the "Back" key, the page with the DataGrid has expired.

So, I there a better solution?
Thanks.
 
Old November 21st, 2006, 03:00 PM
rjd rjd is offline
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there a way to turn off browser caching?





Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDown Dynamic Value Change Master/Detail moizshabbir PHP How-To 1 May 9th, 2008 06:24 AM
Chapter 5 Applying themes to Page Try it Out mcauliff BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 3rd, 2007 11:04 AM
Add dynamic css to master/content page proj-How? VictorVictor ASP.NET 2.0 Basics 6 June 9th, 2006 12:09 PM
Bugbase - superuser not there, tried adding Far BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 April 25th, 2006 01:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.