• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 596
  • Last Modified:

Usercontrol that can be modified at design time

Hi,

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>
</asp:Panel>
 
**** 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

0
rsmaak
Asked:
rsmaak
  • 6
  • 5
1 Solution
 
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.
0
 
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.
0
 
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?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
rsmaakAuthor Commented:
Sorry for the mix up. I mean Webpage.
0
 
Bob LearnedCommented:
What about #2?
0
 
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.

0
 
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.
0
 
rsmaakAuthor Commented:
Do you have a simple example of such a custom user control?

Thanks in advance
0
 
Bob LearnedCommented:
Example:

Walkthrough: Developing and Using a Custom Server Control
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx
0
 
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>
</cc1>.

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
0
 
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
http://www.codeproject.com/KB/custom-controls/ExpandingDiv.aspx

1)  CreateChildControls

protected override void CreateChildControls()

2) ControlDesigner.GetDesignTimeHtml
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now