?
Solved

Usercontrol that can be modified at design time

Posted on 2008-11-03
11
Medium Priority
?
593 Views
Last Modified: 2013-11-05
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
Comment
Question by:rsmaak
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22875681
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
 

Author Comment

by:rsmaak
ID: 22892991
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22895488
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:rsmaak
ID: 22900839
Sorry for the mix up. I mean Webpage.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22901191
What about #2?
0
 

Author Comment

by:rsmaak
ID: 22909236
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22909432
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
 

Author Comment

by:rsmaak
ID: 22919757
Do you have a simple example of such a custom user control?

Thanks in advance
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22921429
Example:

Walkthrough: Developing and Using a Custom Server Control
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx
0
 

Author Comment

by:rsmaak
ID: 22928280
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 750 total points
ID: 22930424
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question