I modified wwWebStoreWebForm.cs accordingly and added Customer.GetThemeByStorePK().
wwWebStoreWebForm.cs is pretty small so I didn't see any harm in adding code there - seem like the best place.
Thanks much,
Craig
/// <summary> /// Override OnPreInit to intercept MasterPage Assignments and theming /// we'll pick up the name of the active theme and apply the master /// page out of the appropriate App_Templates directory. /// /// Must be implemented at this level not the base class or else /// the MasterPageFile is not applied properly. /// </summary> /// <param name="e"></param> protected override void OnPreInit(EventArgs e) { Theme = App.Configuration.Theme; object StorePk = null; if (Context.Session != null) StorePk = Session["StorePk"]; if (StorePk != null) { Customer = WebStoreFactory.GetbusCustomer(); Theme = Customer.GetThemeByStorePK((int)StorePk).Trim(); } else { if (TemplateMasterPage != "LOGIN") { Response.Redirect("~/SiteLogin.aspx"); return; } } if (TemplateMasterPage == "LOGIN") TemplateMasterPage = ""; // Use a templated MasterPage if (TemplateMasterPage != "" && !string.IsNullOrEmpty(Theme)) MasterPageFile = GetThemeTemplatePath(TemplateMasterPage); base.OnPreInit(e); } /// <summary> /// Returns Theme from a customer storepk /// </summary> /// <param name="tnStorePk"></param> /// <returns></returns> public string GetThemeByStorePK(int tnStorePk) { return ExecuteScalar("select theme from wws_stores where Pk = " + tnStorePk.ToString()) as string; }
The Web Store unfortunately wasn't designed with theming in mind originally (and because it was actually really tricky to do that in ASP.NET 1.x when the store started). In more recent years I started using a different approach to apps that allows for easier theming and dynamic theme switching.
I have to look at the store and see if that might be something that can be backfilled at some point.
Anyway, there's no really good way to override this behavior globally without either creating a subclass and then using the new subclass on all your forms (probably the best choice) or alternately updating wwWebForm.
I don't think either are a big problem because it's not very likely you'll be updating with new code from me after extensive modification of the code. The class name override is the least destructive if you do plan to update to later versions I though because the base class override at least would allow you to use feature changes fixes later.
+++ Rick ---
Hi Rick,
What would be the best way to dynamically change the themes depending on store associated with a customer login without modifying the class wwWebStoreWebForm directly? You yell at me every time I do that <bg>...
Maybe that is the best place, because I would rather do it there than every page anyway.
I also don't want to change every "public partial class page... : wwWebStoreWebForm".
Thank you,
Craig
(Interesting you can't jump over a subclass to its parent base class like you can in VFP too.)
Hi Craig,
base.OnPreInit()
You can only call up the inheritance chain one level (ie. just call the base class). AFAIK, there's no way to route back to classes several levels up.
+++ Rick ---
Hi Rick,
What is the best way to override the wwWebStoreWebForm.OnPreInit() in a code behind such as Default.cs and still call the the very base class wwWebStoreBaseForm.OnPreInit() method?
In VFP you could use scope resolution ::
I would like to override the theme and not run base.OnPreInit(e) because it would wipe out my settings, but still want to call the base::OnPreInit(e); (something to that affect).
Maybe I should subclass wwWebStoreWebForm altogether somehow.
Thanks, Craig
Default.cs
/// <summary>
/// Override OnPreInit to intercept MasterPage Assignments and theming
/// we'll pick up the name of the active theme and apply the master
/// page out of the appropriate App_Templates directory.
///
/// Must be implemented at this level not the base class or else
/// the MasterPageFile is not applied properly.
/// </summary>
/// <param name="e"></param>
protected override void OnPreInit(EventArgs e)
{
Theme = "Fishing";
// Use a templated MasterPage
if (TemplateMasterPage != "" && !string.IsNullOrEmpty(Theme))
MasterPageFile = GetThemeTemplatePath(TemplateMasterPage);
base.OnPreInit(e);
}