Reputation:
In the Page load of A control the Page.Header is null when I am attempting to add a reference. Is there anything special I have to do to add a reference to the head of a page from a control.
Maybe a better way to as this is when does Page.Header load or when can it be accessed from a control
Upvotes: 7
Views: 6025
Reputation: 521
Be sure to set your head tag runat="server"
<head runat="server">
..
</head>
otherwise, the reference to Page.Header will always be null.
Upvotes: 20
Reputation: 18153
You can just add an event handler to Page Loaded Event inside Load Event of control and do what you want.
Something like that:
this.Page.LoadComplete += (ObjectSender, ev) =>
{
var mStyle = new Style();
mStyle.BorderWidth = new Unit(5);
Page.Header.StyleSheet.CreateStyleRule(mStyle, null, "body");
};
ps. I used expression lambda for simplicity.
Upvotes: 1