Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > usercontrol inside usercontrol

Reply
Thread Tools

usercontrol inside usercontrol

 
 
Spartaco
Guest
Posts: n/a
 
      07-31-2007
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:

<aspanel 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>
<asplaceHolder ID="ph1" runat="server"></asplaceHolder>
</aspanel>

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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting a property of a control inside a usercontrol, from another usercontrol Fabiano ASP .Net 2 06-03-2005 09:56 AM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 1 12-11-2004 01:28 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:20 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57