views:

35

answers:

2

I need to load different css file depending on the language that the user selects. I need to do this only in my master page.

A: 

you could write the selected language in a cookie. Then in you master page inspect the value saved in the cookie and assign the correct stylesheet.

Am
I am storing my culture info in a session, but i don't know how to load different css file when the culture changes
WingMan20-10
+2  A: 

If you are using the built-in themes and globalization support you could use a httpModule: (untested)

public class PageModule : IHttpModule
{


public void Dispose()
{
}


public void Init(System.Web.HttpApplication context)
{
    context.PreRequestHandlerExecute += Application_PreRequestHandlerExecute;

}

public void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    //Adds a handler that executes on every page request
    HttpApplication application = default(HttpApplication);
    application = (HttpApplication)sender;

    Page page = application.Context.CurrentHandler as Page;

    if ((page != null))
        page.PreInit += Page_PreInit;

}


public void Page_PreInit(object sender, EventArgs e)
{
    //If current context has no session then abort
    if (HttpContext.Current.Session == null)
        return;

    //Get current page context
    Page page = (Page)sender;

    switch (page.Culture) {
        case "en-US":
            page.Theme = "en-USTheme";
            break;
        case "fr-FR":
            page.Theme = "fr-FRTheme";
            break;
        default:
            page.Theme = "DefaultTheme";
            break;
    }

}

}
Hugh Jeffner