C# – Asp.net theme not applied to derived pages

asp.netc

We have an ASP.net 2.0 web application which is using themes set on the application level using web.config. The theme gets applied correctly for any web page that inherits from Page. The problem is that theme doesn't get applied to our base page which is also inherits from Page.

Suppose our base page is called MyBasePage : Page.

page1.aspx which inheretis from Page: Theme Applied.

page2.aspx which inheretis from MyBasePage: Theme not Applied.

What makes it even more confusing is that when we try and debug page2.aspx at Page_Load to check the value of this.Theme it is actually set to our theme but without the styles being applied.

Any suggestions on how to fix this?

Best Answer

Make sure you are using the base keyword to call the appropriate overridden base class members from within your derived class.

public class MyBasePage : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        // Call the base class's OnInit method
        base.OnInit(e);
    }

    protected override void OnLoad(EventArgs e)
    {
       // Call the base class's OnLoad method
       base.OnLoad(e);
    }       
}