Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > CustomControl on webform in designer shows only text

Reply
Thread Tools

CustomControl on webform in designer shows only text

 
 
Pipo
Guest
Posts: n/a
 
      10-11-2004
Hi,

I've made a customcontrol (inherits from system.web.ui.webcontrol)
Everything works fine.

But when I make my customcontrol...and I reference it in an other project
place the control in the toolbox
and drag it on to a webform, I doesnt see my control but text something like
"MyCustomControlsName"

I accpected to see a textbox and a label instead of the text.
When I run the webapplication I see the textbox and label correct.

Why not in the designer?
How can I show my controls on the designer as well?

thanks alot.


 
Reply With Quote
 
 
 
 
Brian Scott
Guest
Posts: n/a
 
      10-12-2004
Hi,

Sound's like you have a composite control with a TextBox and Label control
inside. These types of controls can have prolems rendering themselves at
designtime without a little help. The control's Render method is probably
being called before the Controls collection is created, which is where your
TextBox and Label exist.

If it's a simple enough control that doesn't require a lot of initialization
try adding a call to EnsureChildControls() in each of your control's
properties like the following.

[Description("..."), Category("...")]
public string Text
{
get
{
EnsureChildControls();
object text = ViewState["text"];
if (text == null)
return "";
else
return (String) text;
}
set
{
EnsureChildControls();
textBox1.Text = value;
ViewState["text"] = value;
}
}

What you are doing here is causing your custom control to create it's
Controls collection when you make a call EnsureChildControls(). This in turn
creates your TextBox and Label and they should then render correctly.

If this doesn't work and you still get the same default text rendering at
design time, you probably need to create a custom designer. Custom designers
inherit from the System.Web.UI.Design.ControlDesigner class. They assist
your composite controls in correctly rendering themselves. If the above
doesn't work let me know. I'll assist you in creating a custom designer.
It's not as complicated as it may sound, so don't worry

"Pipo" wrote:

> Hi,
>
> I've made a customcontrol (inherits from system.web.ui.webcontrol)
> Everything works fine.
>
> But when I make my customcontrol...and I reference it in an other project
> place the control in the toolbox
> and drag it on to a webform, I doesnt see my control but text something like
> "MyCustomControlsName"
>
> I accpected to see a textbox and a label instead of the text.
> When I run the webapplication I see the textbox and label correct.
>
> Why not in the designer?
> How can I show my controls on the designer as well?
>
> thanks alot.
>
>
>

 
Reply With Quote
 
 
 
 
Robert Koritnik
Guest
Posts: n/a
 
      10-12-2004
What you're missing is a custom control designer class that should be used
for design time control rendering and work with... MSDN should be of enough
help. For the kind of a control that you have it's rather simple to make
one.

--
RobertK


"Pipo" <> wrote in message
news:#...
> Hi,
>
> I've made a customcontrol (inherits from system.web.ui.webcontrol)
> Everything works fine.
>
> But when I make my customcontrol...and I reference it in an other project
> place the control in the toolbox
> and drag it on to a webform, I doesnt see my control but text something

like
> "MyCustomControlsName"
>
> I accpected to see a textbox and a label instead of the text.
> When I run the webapplication I see the textbox and label correct.
>
> Why not in the designer?
> How can I show my controls on the designer as well?
>
> thanks alot.
>
>



 
Reply With Quote
 
Pipo
Guest
Posts: n/a
 
      10-12-2004
Thanks for helping Brain,

I helped but when I put the control on my form the first time its still
text.
When I drag it to an other place on the form the control looks fine!

Can you help me with the custom designer?
I tried the MSDN first but I think I dont understand it....(yet anyway)


thanks again!

Can you help me with

"Brian Scott" <> schreef in bericht
news:44BB0F32-29D4-4C09-AA8E-...
> Hi,
>
> Sound's like you have a composite control with a TextBox and Label control
> inside. These types of controls can have prolems rendering themselves at
> designtime without a little help. The control's Render method is probably
> being called before the Controls collection is created, which is where
> your
> TextBox and Label exist.
>
> If it's a simple enough control that doesn't require a lot of
> initialization
> try adding a call to EnsureChildControls() in each of your control's
> properties like the following.
>
> [Description("..."), Category("...")]
> public string Text
> {
> get
> {
> EnsureChildControls();
> object text = ViewState["text"];
> if (text == null)
> return "";
> else
> return (String) text;
> }
> set
> {
> EnsureChildControls();
> textBox1.Text = value;
> ViewState["text"] = value;
> }
> }
>
> What you are doing here is causing your custom control to create it's
> Controls collection when you make a call EnsureChildControls(). This in
> turn
> creates your TextBox and Label and they should then render correctly.
>
> If this doesn't work and you still get the same default text rendering at
> design time, you probably need to create a custom designer. Custom
> designers
> inherit from the System.Web.UI.Design.ControlDesigner class. They assist
> your composite controls in correctly rendering themselves. If the above
> doesn't work let me know. I'll assist you in creating a custom designer.
> It's not as complicated as it may sound, so don't worry
>
> "Pipo" wrote:
>
>> Hi,
>>
>> I've made a customcontrol (inherits from system.web.ui.webcontrol)
>> Everything works fine.
>>
>> But when I make my customcontrol...and I reference it in an other project
>> place the control in the toolbox
>> and drag it on to a webform, I doesnt see my control but text something
>> like
>> "MyCustomControlsName"
>>
>> I accpected to see a textbox and a label instead of the text.
>> When I run the webapplication I see the textbox and label correct.
>>
>> Why not in the designer?
>> How can I show my controls on the designer as well?
>>
>> thanks alot.
>>
>>
>>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-13-2004
Hi Pipo,

As for defining a Custom ControlDesigner for a custom webcontrol, we can
follow the following steps:

1. Create a custom controldesigner, for example:

========Control Designer class=============
public class TestControlDesigner : System.Web.UI.Design.ControlDesigner
{

public override string GetDesignTimeHtml()
{
string html = "";
html = "<center><div>This is the design-time html!</div></center>"

return html;
}
.....................

}

# The "GetDesignTimeHtml" method just help to provide the html that will
be output at the control's design-time(in IDE). It'll override the default
behavior of the control

#ControlDesigner.GetDesignTimeHtml Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemWebUIDesignControlDesignerClassGetDesig nTimeHtmlTopic.asp


2. Apply the Custom Designer onto our CustomControl, just use the
"Designer" Attribute, such as:

[DefaultProperty("Text"),
ToolboxData("<{0}:TestControl runat=server></{0}:TestControl>"),
Designer(typeof(TestControlDesigner))]
public class TestControl : System.Web.UI.Control
{

In addition, here is a good tech article which has a complete tutorial on
developing a custom webcontrol and add rich design-time support for it.
(such as Control Designer, IDE intellisense ...)

#Adding Design-Time Support to ASP.NET Controls
http://msdn.microsoft.com/library/de...us/dnaspp/html
/ASPNet-AddDesignTimeSupport.asp


Hope helps. Thanks

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





 
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
IE shows false and Firefox shows true Gianni Javascript 3 07-10-2009 09:18 PM
writing a customControl philipp ASP .Net 2 05-18-2005 03:40 AM
Session var in page_load shows old value, buttonclick shows new . Whats wrong gce ASP .Net 0 05-07-2005 06:50 AM
A HtmlControl as Customcontrol Property KMILO ASP .Net 0 04-22-2005 09:17 PM
CustomControl - Not triggering on an empty field. Eric B ASP .Net 1 09-03-2003 09:24 AM



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