J
jacobya
I realize this question has been asked in many different newsgroups,
but reading through these discussions and the vague examples that come
with the documentation, I have still not got a good idea on the best
approach for coming up with some type of templating solution. I have
looked at the Master Pages approach and I personally think it is too
cumbersome and confusing. I would like to have a design-view friendly
solution that junior developers can use quickly and easily. I'm
currently investigating the templated control approach and what I
would like to have is the following:
_______________
|
| Static Header
|______________
|
| Drag and Drop
| Content Area
|______________
|
| Static Footer
|______________
My question is this: is a templated control the best approach for
accomplishing this, and will it allow me to maintain a drag-and-drop,
design-view friendly content area (that allows for GridLayout or
FlowLayout). If so, does anyone have any code samples of how this can
be done that they'd be willing to share? Below is the code that I
have so far, but it's still nowhere near where it needs to be.
// Master container control that will hold header, footer and content
controls
using System.ComponentModel;
using System.Web.UI.Design;
using System.Collections;
using System.Web.UI.WebControls;
namespace CustomControls
{
[Designer(typeof(ReadWriteControlDesigner))]
[ParseChildren(true)]
[PersistChildren(true)]
public class TemplateControl : Control, INamingContainer
{
public HeaderControl header;
public ContentControl content;
public FooterControl footer;
public TemplateControl()
{}
public String Text
{
get
{
return header.Text + "<br>" + content.Text + "<br>" + footer.Text;
}
}
}
// ****************** Header Control **********************
using System;
using System.Web;
using System.Web.UI;
namespace CustomControls
{
[ParseChildren(true)]
public class HeaderControl : Control, INamingContainer
{
private ITemplate template;
private String text = "Header";
private Control myTemplateContainer;
protected override void OnDataBinding(EventArgs e)
{
EnsureChildControls();
base.OnDataBinding(e);
}
[TemplateContainer(typeof(TemplateControl))]
public ITemplate Template
{
get
{
return template;
}
set
{
template = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Control MyTemplateContainer
{
get
{
return myTemplateContainer;
}
}
protected override void CreateChildControls ()
{
if (Template != null)
{
myTemplateContainer = new TemplateControl();
((TemplateControl)MyTemplateContainer).header = this;
Template.InstantiateIn(myTemplateContainer);
Controls.Add(myTemplateContainer);
}
else
{
Controls.Add(new LiteralControl(Text));
}
}
}
}
// ****************** Content Control **********************
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;
namespace CustomControls
{
[Designer(typeof(ReadWriteControlDesigner))]
[ParseChildren(true)]
[PersistChildren(true)]
public class ContentControl : WebControl
{
private ITemplate template;
private String text = "Content";
private Control myTemplateContainer;
public ContentControl()
{}
protected override void OnDataBinding(EventArgs e)
{
EnsureChildControls();
base.OnDataBinding(e);
}
[TemplateContainer(typeof(TemplateControl))]
public ITemplate Template
{
get
{
return template;
}
set
{
template = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Control MyTemplateContainer
{
get
{
return myTemplateContainer;
}
}
protected override void CreateChildControls ()
{
if (Template != null)
{
myTemplateContainer = new TemplateControl();
((TemplateControl)MyTemplateContainer).content = this;
Template.InstantiateIn(myTemplateContainer);
Controls.Add(myTemplateContainer);
}
else
{
//Controls.Add(new LiteralControl(Text));
}
}
}
}
// ****************** Footer Control **********************
using System;
using System.Web;
using System.Web.UI;
namespace CustomControls
{
[ParseChildren(true)]
public class FooterControl : Control, INamingContainer
{
private ITemplate template;
private String text = "Footer";
private Control myTemplateContainer;
protected override void OnDataBinding(EventArgs e)
{
EnsureChildControls();
base.OnDataBinding(e);
}
[TemplateContainer(typeof(TemplateControl))]
public ITemplate Template
{
get
{
return template;
}
set
{
template = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Control MyTemplateContainer
{
get
{
return myTemplateContainer;
}
}
protected override void CreateChildControls ()
{
if (Template != null)
{
myTemplateContainer = new TemplateControl();
((TemplateControl)MyTemplateContainer).footer = this;
Template.InstantiateIn(myTemplateContainer);
Controls.Add(myTemplateContainer);
}
else
{
Controls.Add(new LiteralControl(Text));
}
}
}
}
Many thanks and sorry for the long post.
but reading through these discussions and the vague examples that come
with the documentation, I have still not got a good idea on the best
approach for coming up with some type of templating solution. I have
looked at the Master Pages approach and I personally think it is too
cumbersome and confusing. I would like to have a design-view friendly
solution that junior developers can use quickly and easily. I'm
currently investigating the templated control approach and what I
would like to have is the following:
_______________
|
| Static Header
|______________
|
| Drag and Drop
| Content Area
|______________
|
| Static Footer
|______________
My question is this: is a templated control the best approach for
accomplishing this, and will it allow me to maintain a drag-and-drop,
design-view friendly content area (that allows for GridLayout or
FlowLayout). If so, does anyone have any code samples of how this can
be done that they'd be willing to share? Below is the code that I
have so far, but it's still nowhere near where it needs to be.
// Master container control that will hold header, footer and content
controls
using System.ComponentModel;
using System.Web.UI.Design;
using System.Collections;
using System.Web.UI.WebControls;
namespace CustomControls
{
[Designer(typeof(ReadWriteControlDesigner))]
[ParseChildren(true)]
[PersistChildren(true)]
public class TemplateControl : Control, INamingContainer
{
public HeaderControl header;
public ContentControl content;
public FooterControl footer;
public TemplateControl()
{}
public String Text
{
get
{
return header.Text + "<br>" + content.Text + "<br>" + footer.Text;
}
}
}
// ****************** Header Control **********************
using System;
using System.Web;
using System.Web.UI;
namespace CustomControls
{
[ParseChildren(true)]
public class HeaderControl : Control, INamingContainer
{
private ITemplate template;
private String text = "Header";
private Control myTemplateContainer;
protected override void OnDataBinding(EventArgs e)
{
EnsureChildControls();
base.OnDataBinding(e);
}
[TemplateContainer(typeof(TemplateControl))]
public ITemplate Template
{
get
{
return template;
}
set
{
template = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Control MyTemplateContainer
{
get
{
return myTemplateContainer;
}
}
protected override void CreateChildControls ()
{
if (Template != null)
{
myTemplateContainer = new TemplateControl();
((TemplateControl)MyTemplateContainer).header = this;
Template.InstantiateIn(myTemplateContainer);
Controls.Add(myTemplateContainer);
}
else
{
Controls.Add(new LiteralControl(Text));
}
}
}
}
// ****************** Content Control **********************
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;
namespace CustomControls
{
[Designer(typeof(ReadWriteControlDesigner))]
[ParseChildren(true)]
[PersistChildren(true)]
public class ContentControl : WebControl
{
private ITemplate template;
private String text = "Content";
private Control myTemplateContainer;
public ContentControl()
{}
protected override void OnDataBinding(EventArgs e)
{
EnsureChildControls();
base.OnDataBinding(e);
}
[TemplateContainer(typeof(TemplateControl))]
public ITemplate Template
{
get
{
return template;
}
set
{
template = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Control MyTemplateContainer
{
get
{
return myTemplateContainer;
}
}
protected override void CreateChildControls ()
{
if (Template != null)
{
myTemplateContainer = new TemplateControl();
((TemplateControl)MyTemplateContainer).content = this;
Template.InstantiateIn(myTemplateContainer);
Controls.Add(myTemplateContainer);
}
else
{
//Controls.Add(new LiteralControl(Text));
}
}
}
}
// ****************** Footer Control **********************
using System;
using System.Web;
using System.Web.UI;
namespace CustomControls
{
[ParseChildren(true)]
public class FooterControl : Control, INamingContainer
{
private ITemplate template;
private String text = "Footer";
private Control myTemplateContainer;
protected override void OnDataBinding(EventArgs e)
{
EnsureChildControls();
base.OnDataBinding(e);
}
[TemplateContainer(typeof(TemplateControl))]
public ITemplate Template
{
get
{
return template;
}
set
{
template = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Control MyTemplateContainer
{
get
{
return myTemplateContainer;
}
}
protected override void CreateChildControls ()
{
if (Template != null)
{
myTemplateContainer = new TemplateControl();
((TemplateControl)MyTemplateContainer).footer = this;
Template.InstantiateIn(myTemplateContainer);
Controls.Add(myTemplateContainer);
}
else
{
Controls.Add(new LiteralControl(Text));
}
}
}
}
Many thanks and sorry for the long post.