Reputation: 1
I want create a user control (Div) like panel to be used in all my web pages. For example, The UserControl can have two DIVs or TRs with a background design. If it's added to a Page, the UserControl has to allow controls to be added into it, i.e. Divs, Labels, and TextBoxes. The height of the div should be AUTO. Please help me.
Upvotes: 0
Views: 829
Reputation: 68506
Add the following property to your UserControl:
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[TemplateInstance(TemplateInstance.Single)]
public ITemplate Content
{
get
{
return _content;
}
set
{
_content = value;
}
}
private ITemplate _content;
Then handle the the Content in the CreateChildControls method:
protected override void CreateChildControls()
{
if (this.Content != null)
{
this.Content.InstantiateIn(this);
}
base.CreateChildControls();
}
In markup you can now add anything you want into the Content tags of the Control:
<ctl:YourControl runat="server" ID="Foo" style="background-color:#666">
<Content>
<asp:Label ... />
<asp:TextBox... />
</Content>
</ct1:YourControl>
Upvotes: 3
Reputation: 54979
write the control panel code on a different page.
on the pages check if its needed and include the control panel. if there are other elements on the page which will need special controls.
you can do a if() and add the controls there.
Upvotes: 0