Initialization in Asp.NET Master Page
I need to do a dynamically loaded Header and Footer on Master page where there are two placeholders to store the users controls which will become the Headers and Footers. The reason why I am doing it to make it more customizable and it is the how it is required from my supervisor as well.
So I have two key-value in web.config such as
<add key="MasterHeader" key="~/Controls/Header.ascx"/>
<add key="MasterFoo开发者_开发技巧ter" key="~/Controls/Footer.ascx"/>
So I am wondering which Page event should I load these users controls by saying
UserControl uc = (UserControl) Page.LoadControl(ConfigFile.MasterHeader))
PlaceHolder1.Controls.Add(uc)
- Where is the best Page event to put the codes above?
- Do I need to put something in the page directive to make it work?
I would use OnPreInit or OnPreLoad. You shouldn't need to put anything in the page directive to make this work, the way you're describing it.
精彩评论