Usercontrol that can be modified at design time


I want to create a User Control in VS 2008 that allows you to add/resize/move controls at design time so i can use it as a template. Problem is that when i create a user control, it appears somehow as a single control when I drop it on a form. I have attached a snippet with a simple panel, a label and a textbox. When I drop this control on a form, i cannot add extra controls to it or something. I searched internet and found info on templated controls, custom designers but non of these gave me something simple that would resolve this issue.  The snippets contains the code from the user control WebUsercontrol1.ascx

Anyone knows?
**** Contents of WebUserControl1.ascx *****
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="Demo.WebUserControl1" %>
<asp:Panel ID="Panel1" runat="server">
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
**** Contents of WebUserControl1.ascx.cs *****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SimpleTest
    public partial class WebUserControl1 : System.Web.UI.UserControl

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
If you need for the user control to be a "container" control, I would think that you need to inherit from a container control, like Panel, instead of UserControl.
rsmaakAuthor Commented:
Well I wish it was that easy. Changing Usercontrol into Panel shows the exact same result. A control that cannot be modified when dropped on a form.
Bob LearnedCommented:
1) When you say "form", do you mean Windows Forms, or "page" for web page?

2) If you drop a Panel on the page, does it work as expected?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

rsmaakAuthor Commented:
Sorry for the mix up. I mean Webpage.
Bob LearnedCommented:
What about #2?
rsmaakAuthor Commented:
If i drop a normal (standard) panel. It works as expected. Its the usercontrol that is the problem. The steps to reproduce this are realy simple:
1. create a new web project
2. add a new item of type Web User control named MyUsercontrol.ASCX
3. Drop a panel on the design surface of the ASCX file
4. drop a label and a textbox inside the panel
5 Drag and drop MyUsercontrol on the default page Default.ASPX

Then you see the control but you cant select the label or textbox inside. It became one grouped thing. Its impossible to add something else to the panel.

I hope this explains it a bit better.

Bob LearnedCommented:
I was thinking custom user control, and you were talking about a UserControl.  Those are two different things.  If you want a control that you can use at design-time, then you need a custom user control, that generates design-time HTML.
rsmaakAuthor Commented:
Do you have a simple example of such a custom user control?

Thanks in advance
Bob LearnedCommented:

Walkthrough: Developing and Using a Custom Server Control
rsmaakAuthor Commented:
I already found that Example on the internet, among lots of others. What this example and all the others doesnt give me is the children. The children wont be exposed in design time. I can add properties to the children that i can set on the parent level and perform action on the child controls but that isnt te issue. I want when i click with my mouse on the textbox inside custom server control the it wil be selected. In code i get <cc1:MyControl  ID = "MyControl1" RunAt=Server>.
I want the textbox, label HTML to be generated so i can actually select them and adress them in my codebehind. Such as:  (i did not copy it from VS so ignore formatting or typo's)
<cc1:MyControl> ID = "MyControl1">
     <asp:label id=MyLabel runat=server>
     <asp:textbox id=MyTextbox runat=server>

After more searching I starting to think its impossible without designing complicated renderers. If you can confirm this ill just give up the idea and wait for VS 2009 :)

P.S. I come from a foxpro environment. Things like thisis super easy there. Im used to building a framework this way. I design the shell in a framework and modify it (add code to methods, resize the class, add method, properties)  at design time.

Thanks for replying all the time TLO
Bob LearnedCommented:
Yep, changing from one development environment to another can be very frustrating.  Welcome to the "wonderful" world of .NET!!

I believe that you need a proof-of-concept to overcome your problem.

ExpandingTable with Design-Time support

1)  CreateChildControls

protected override void CreateChildControls()

2) ControlDesigner.GetDesignTimeHtml

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.