In the end of 2007, i worked for a big company that still used in their sites asp.net 1.1. In fact, in their main site, the entire middleware is made in C# 1.1 (their site was launch at the beginning of 2008).
For this reason, there must still exist several applications made in ASP.NET 1.1 that will need some maintenance and new developments.
The challenge here is to develop a control that can simulate master pages in asp.net 1.1 similar to the one that exists in asp.net 2.0+. You make the master page using a .ascx control and make a .aspx webform has you would make in asp.net 2.0, meaning:
<asp:placeholder id='placeholder' runat="server"/>
<ctrl:contentplaceholder master="Master.ascx" runat="server"> YOUR CONTENT </ctrl:contentplaceholder>
where contentplaceholder is the control described below and master the name of the file of your master page. Has you will see below in the code, you can also omit this field and configure it’s value in the app settings of the web.config:
The code control is simple has below:
public class ContentPlaceholder : Control {
private string masterPage;
public string MasterPage {
get {
if( masterPage == null ||
masterPage == string.Empty ) {
return "~/" +
ConfigurationSettings.AppSettings["MasterPage"];
}
return masterPage;
}
set { masterPage = value; }
}
private void ChangeControls( Control src, Control dst ) {
while( src.Controls.Count > 0 ){
Control c = src.Controls[0];
src.Controls.Remove( c );
dst.Controls.Add( c );
}
}
private void LoadMaster( Control master ) {
PlaceHolder contentPlaceholder = (PlaceHolder)
master.FindControl( "placeholder" );
ChangeControls( this, contentPlaceholder );
ChangeControls( master, this );
}
protected override void OnInit(EventArgs e) {
Control master = Page.LoadControl( MasterPage );
LoadMaster( master );
}
}
In Resume, in the OnInit event the controls of the web page are removed from the aspx page, the content of the master page is inserted in the aspx, and the content previously removed is inserted in the placeholder of the master page:
I hope this example helps someone that still work with the old framework 1.1. This can be handy in big projects where you have hundreds of aspx to change.