S
Spartaco
My purpose is whenever I want to make a new UserControl, to have a property
in the userControl's base class to decide if a frame around the usercontrol
should be visible or not.
Since I want the ability to personalize the frame, I have created a
UserControl with a PlaceHolder where other controls should be inserted:
<asp
anel id="panel" runat="server" CssClass="frame">
<table id="title" class="titleFrame" runat="server" cellpadding="0"
cellspacing="0">
<tr><td class="first"><h3 id="lblTitle" runat="server"></h3></td>
<td>
<asp:Image id="img" runat="server" AlternateText="Zoom" />
</td>
</tr>
</table>
<asp
laceHolder ID="ph1" runat="server"></asp
laceHolder>
</asp
anel>
Now I want a base class for UserControls, with a property to set the frame
visible, this class will also load my frame and will move the child controls
to the placeholder contained in the frame:
public class BaseUserControl : UserControl
{
#region fields
bool _frameVisible;
string _frameTitle;
PlaceHolder ph1;
List<Control> ctls = new List<Control>();
#endregion
#region constructor
public BaseUserControl()
{
}
#endregion
#region properties
public bool FrameVisible
{
get{return _frameVisible;}
set{_frameVisible = value;}
}
public string FrameTitle
{
get{return _frameTitle;}
set{_frameTitle = value;}
}
#endregion
#region overrides
protected override void AddParsedSubObject(object obj)
{ctls.Add((Control)obj);}
protected override void CreateChildControls()
{
if (_frameVisible) {
Control frame = Page.LoadControl("~/Frame.ascx");
frame.ID = "frame";
ph1 = (PlaceHolder)frame.FindControl("ph1");
HtmlGenericControl title =
(HtmlGenericControl)frame.FindControl("lblTitle");
title.InnerHtml = _frameTitle;
this.Controls.Add(frame);
}
base.CreateChildControls();
foreach (Control ctl in ctls) {
if (_frameVisible) {
ph1.Controls.Add(ctl);
} else {
Controls.Add(ctl);
}
}
}
#endregion
}
This approch seems to work, but there is a problem with DropDownLists
viestate, any other controls seems to work correctly after a postback, but
DropDownLists no. I suspect because these controls uses the interface
IPostBackDataHandler and my approch breaks something, but I don't understand
what...
any help?
in the userControl's base class to decide if a frame around the usercontrol
should be visible or not.
Since I want the ability to personalize the frame, I have created a
UserControl with a PlaceHolder where other controls should be inserted:
<asp
<table id="title" class="titleFrame" runat="server" cellpadding="0"
cellspacing="0">
<tr><td class="first"><h3 id="lblTitle" runat="server"></h3></td>
<td>
<asp:Image id="img" runat="server" AlternateText="Zoom" />
</td>
</tr>
</table>
<asp
</asp
Now I want a base class for UserControls, with a property to set the frame
visible, this class will also load my frame and will move the child controls
to the placeholder contained in the frame:
public class BaseUserControl : UserControl
{
#region fields
bool _frameVisible;
string _frameTitle;
PlaceHolder ph1;
List<Control> ctls = new List<Control>();
#endregion
#region constructor
public BaseUserControl()
{
}
#endregion
#region properties
public bool FrameVisible
{
get{return _frameVisible;}
set{_frameVisible = value;}
}
public string FrameTitle
{
get{return _frameTitle;}
set{_frameTitle = value;}
}
#endregion
#region overrides
protected override void AddParsedSubObject(object obj)
{ctls.Add((Control)obj);}
protected override void CreateChildControls()
{
if (_frameVisible) {
Control frame = Page.LoadControl("~/Frame.ascx");
frame.ID = "frame";
ph1 = (PlaceHolder)frame.FindControl("ph1");
HtmlGenericControl title =
(HtmlGenericControl)frame.FindControl("lblTitle");
title.InnerHtml = _frameTitle;
this.Controls.Add(frame);
}
base.CreateChildControls();
foreach (Control ctl in ctls) {
if (_frameVisible) {
ph1.Controls.Add(ctl);
} else {
Controls.Add(ctl);
}
}
}
#endregion
}
This approch seems to work, but there is a problem with DropDownLists
viestate, any other controls seems to work correctly after a postback, but
DropDownLists no. I suspect because these controls uses the interface
IPostBackDataHandler and my approch breaks something, but I don't understand
what...
any help?