help.axcms.netAxinom Logo
Save Save Chapter Send Feedback
KB10010: Page.Header is not accessible from a Custom Editor for a Structure Element
If you try to access Page.Header, you cannot add anything to the Head-element of the ASPX-page, because In the Management System of AxCMS.net a master page approach is in use

SYMPTOMS

If you try to access Page.Header, it is null, so you cannot add anything to the Head-element of the ASPX-page. For example it is not possible to add your custom CSS file to a Custom Editor for a Structure Element.

CAUSE

In the Management System of AxCMS.net a master page approach is in use, which does not use aspx-like head-element (<head runat="server">). The approach is similar to ASP.NET Master Pages, but not exactly this one - it AxCMS.net is was implemented before it came with ASP.NET. This is why the standard ASP.NET property Page.Header is just null.

SOLUTION

All aspx-pages in Management System are ultimately inherited from the class AxCMS.BL.BaseHtmlPage, which does provide a head-property:

protected HtmlGenericControl Head;

Having access to it, you could add custom content into the head section like this:

Page.Head.Controls.Add(new LiteralControl("..."));

The problem is - as you see, this property is protected, and if you do not control the aspx-page, you cannot easily access it.

A workaround would be to use reflection to access this property:

Type t = this.Page.GetType();
FieldInfo fld = t.GetField("_Head", BindingFlags.Instance | BindingFlags.NonPublic);
HtmlGenericControl head = fld.GetValue(this.Page) as HtmlGenericControl;
head.Controls.Add(new LiteralControl(string.Format("<link href=\"{0}\"type=\"text/css\" rel=\"stylesheet\" />", "path to CSS")));

Axinom will consider to change this in the future versions of AxCMS.net

MORE INFORMATION

APPLIES TO

AxCMS.net versions: All versions