CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 1/17/2006 4:55:10 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 7 Views: 35 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
8 Items, 1 Pages 1 |< << Go >> >|
mjolley
Asp.Net User
Is there a more efficient way to apply themes dynamically?1/17/2006 4:55:10 AM

0/0

Right now I'm loading themes based on the user that logs in, but to do it I have to add the following code to the code behind of every page:

Dim Users As New Users
Dim UI As New Users.UserInfo
UI = Users.User_GetInfo(User.Identity.Name)

If Len(UI.Theme) > 0 Then
    Page.Theme = Server.HtmlEncode(UI.Theme)
Else
    Page.Theme = Server.HtmlEncode("Default")
End If

If there's a more efficient way to do this please let me know because I hate code like this.
jhouse
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?1/17/2006 3:52:17 PM

0/0

create a base class for all of your pages

in the base class you can implement this code in the OnInIt method or in the Page_Load, if you do this in Page_Load you would need to call the base class each time

I don't know what this looks like in vb.net but in c# it something like

public class PageBase : System.Web.UI.Page
{
  public void OnPageLoad(Object sender, System.EventArgs e)
  {
     // your theme loading code goes here
  }
}

// the rest of your pages
public class SomePage : PageBase
{
  public void Page_Load(Object sender, System.EventArgs e)
  {
    base.OnPageLoad(sender, e);

    // the rest of your page specific code
  }  
}

It is better if you put this in OnInIt as then it will happen 'automatically' and you will not have to call base.OnPageLoad (i guess this is MyBase in vb.net)

another way to do it if you don't want to get into inheritance
create a Util object

public class Util
{
  public static void LoadTheme(System.Web.UI.Page page, HttpContext.Current.User user)
  {
    // load your theme  
  }
}

// the rest of your pages
public class SomePage : System.Web.UI.Page
{
  public void Page_Load(Object sender, System.EventArgs e)
  {
    Util.LoadTheme(this, User);

    // the rest of your page specific code
  }  
}
mjolley
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?1/17/2006 5:15:37 PM

0/0

I think that is perfect.  I knew there was something to do with inheritance, but I've never really used it.  Thanks for the response.  Now that I  see a basic way to do that I'm going to be doing it everywhere.
SimonCal
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?1/17/2006 6:46:43 PM

0/0

Dynamically setting the Theme should always be done in Page_PreInit.This means that any post-back values for example will be hanbdled correctly and override those potentially from the Theme
Simon
This posting is provided "AS IS" with no warranties, and confers no rights.
mjolley
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?1/17/2006 6:51:35 PM

0/0

Yeah, I knew that i should do it in PreInit.  So I'm just doing it in my PageBase class then inheriting that from all other pages.  Works great!
Dave Sussman
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?1/18/2006 9:38:11 AM

0/0

Personally I use an HttpModule, for two reasons.

1. If a Theme is a global feature, applied to every page, then it should be applied at the global level, not the page level.

2. You don't have to create a base class and modify the inheritance of each page class. Especially useful when developing sites and adding new pages.

This is actually really easy to do. Here's the module I use (C#, but I have a VB version if anyone needs it):

using System;
using System.Web;
using System.Web.UI;

namespace ipona.Web.GlobalEvents
{
  public class ThemeModule : IHttpModule
  {
    public void Init(HttpApplication context)
    {
      context.PreRequestHandlerExecute +=
       new EventHandler(this.app_PreRequestHandlerExecute);
    }

    private void app_PreRequestHandlerExecute(object Sender, EventArgs E)
    {
      Page p = HttpContext.Current.Handler as Page;
      if (p != null)
      {
        ProfileCommon pb = (ProfileCommon)HttpContext.Current.Profile;
        p.Theme = pb.Theme;
      }
    }

    public void Dispose()
    {
    }
  }
}

This assumes the Theme is stored in a Profile property called Theme. Then add the module in web.config:

    <httpModules>
      <add name="Page" type="ipona.Web.GlobalEvents.ThemeModule" />
    </httpModules>

The great thing about this is that once plugged in you don't have to do anything else.

Simon - if this is a 'bad' thing to do then do let me know.

Dave

 

SimonCal
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?1/18/2006 11:07:25 PM

0/0

Dynamically, for global settings, there are a number of ways of doing it and depending upon situation and avoiding a base page might make sense. In the module manner all pages get this behavior, which could be locally overriden I guess, using a base page class means that you can avoid that I suppose .. :)

You could do your global work in global.asax, using the same code listed in the previous post, in say Application_Start and avoid having a new module and config entries..

 

 


Simon
This posting is provided "AS IS" with no warranties, and confers no rights.
Brian Womack Ph
Asp.Net User
Re: Is there a more efficient way to apply themes dynamically?5/5/2006 12:23:48 PM

0/0

I love the HttpModule method.  It works great, except for one problem.

I use Infragistics WebMenu, and it breaks that.  Can you suggest a different event to handle?

Brian Womack
Innovative Patterns Corp.
8 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Will Europe Work?: Integration, Employment and the Social Order Authors: Martin Kohli, Mojca Novak, Pages: 201, Published: 2001
Handbook of Chronic Pain Authors: Shulamith Kreitler, Diego Beltrutti, Pages: 600, Published: 2007
Performance Management in Health Care: Improving Patient Outcomes : an Integrated Approach Authors: Jan Walburg, Pages: 229, Published: 2006
Service-oriented Computing--ICSOC 2003: First International Conference, Trento, Italy, December 15-18, 2003 : Proceedings Authors: Maria E. Orlowska, Sanjiva Weerawarana, Michael P. Papazoglou, Jian Yang, Pages: 576, Published: 2003
Reinforcement Learning: An Introduction Authors: Richard S. Sutton, Andrew G. Barto, Pages: 322, Published: 1998
Leonardo's Machines: Da Vinci's Inventions Revealed Authors: Domenico Laurenza, Mario Taddei, Edoardo Zanon, Pages: 240, Published: 2006

Web:
MacThemes Forum / WinterBoard ("SummerBoard" for 2.0) HM I apply my theme in Winterboard and respring but it does not apply. hmm. Offline .... There may be more efficient ways to do it. ...
Gayle Di Pietro & Ian Hughes Dynamic Outcomes Pty Ltd ABSTRACT TravelSMART Schools – there really is a better way to go! ... cycling, public transport and identifies alternative and more efficient ways to use the ...
Mira - Themes The dynamic process of the user-system interaction must be taken into account in ... In such systems, the way to handle this access is more complex than in ...
Themes and Master Pages One of the most common ways to apply standardized formatting is to use CSS ..... Here’s an example that applies a dynamic theme by reading the theme name ...
Virtual Ecosystems Virtual ecosystems are realistic spatial dynamic simulations representing ... There is a need for more efficient interaction between physical and behavioral ...
Drupal 6 Themes By way of example, we take a default theme and customize it using only the ... and extensions that make your work with themes easier and more efficient. ...
HIV/AIDS themes This should encourage the more efficient use of scarce resources and allow ... keep a constant, two-way flow of information to and from their partners, ...
dtcnet.co.uk » dTabs (Dynamic Tabs) - Wordpress Plugin Please feel free to add any more themes to list by commenting on this post :-) ..... Just one question, is there any way to make it work with the qTranslate ...
WPelements.com Press75.com is now open for business to make the entire process of purchasing themes and receiving support for purchased themes more efficient for my . ...
More Efficient SyntaxHighlighter As it turns out loading JavaScript dynamically can be a little puzzling for some ... More Efficient SyntaxHighlighter. I read a thread somewhere about how ...

Videos:
A New Way to look at Networking Google Tech Talks August 30, 2006 Van Jacobson is a Research Fellow at PARC. Prior to that he was Chief Scientist and co-founder of Packet Design. P...
Silicon Valley WebGuild: Vertical Search Trends Google Tech Talks August 23, 2006 Silicon Valley Web Guild http://www.webguild.org/ Presenters: Michael Yang, Founder, President and CEO, Become.co...




Search This Site:










why no transparency?!

asp.net

window app style menus at the top

sitemappath control and showstartingnode="false" behavior

passing parameter from one user control to another

find all div ids on a master page

master pages, styles and ids

how to access master page datalist from a content page ?

defaultbutton for panel? webform uses masterpage.

treeview - getting selected node from content page

protected sub page_load and public readonly property

'unable to cast object of type' error

non-static metadata using master pages?

redirect problem in master page

treeview

is there a way to hide a menu item?

master page menus and content page controls

how do you change the border color when mouse hover over a linkbutton?

theme & cookie

looking for a better menuadapter implementation, because the default ain't finished.

classic theme...

treeview and populateondemand - do enableclientscript, populatenodesfromclient work?

dynamic theme control in (mobile) web site (vs2.0)?

tree view

sitemappath - formatting 'visited' links

how to access the root master page if master pages are nested?

sitemapprovider cannot be found

sitemappath for edit and insert

help with treeview (asp.net 2.0)

is there a sample masterpage themes gallery

  Privacy | Contact Us
All Times Are GMT