design time support for composite controls....

S

scsharma

Hi,
I am creating composite control which consists of there textboxes.I derived
that composite control from WebControl, INamingContainer. I am creating
constituent controls and adding those controls to controls collection in the
CreateChildControls() method.
I was under the impression that when this composite controlled is dragged
and dropped on web form in IDE then constituent controls are automatically
rendered by IDE. That's not happening. In design time when i drag and drop
this control on webform, i am seeing "ControlType:COntrolID"
(AOCControl:AocControl1") text. But when i run the form i see the constituent
controls.
Initially i did not expose any public properties for this composite
control. But when i exposed some fake public properties and called
EnsureChildControls(); from those properties then I could see the constituent
control only when this public property is modified.
Any help is appreciated.
 
B

Brock Allen

You need to implement a ControlDesiger-derived class to get design time HTML.
 
S

Steven Cheng[MSFT]

Thanks for Brock's informative inputs.

Hi SCSharma,

The problem that VS.NET ide DISPLAY nothing for composite contorl is
because VS.NET webform design-view by default will look for the
WebControl's "Render" method to get the design-time HTML to display. Since
composite control didn't use the "Render" method for displaying, so there
will have nothing at design-view. AS Brock has mentioned, we can supply a
custom ControlDesigner for our control. The ControlDesigner has a
"GetDesignTimeHtml" overrideable function which is used to generate the
html displayed at design-time in VS.NET ide.

#Implementing a Simple Web Forms Control Designer
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhtmldesignersample
..asp?frame=true

Hope also helps.Thanks,

Steven Cheng
Microsoft Online Support

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



--------------------
| Message-ID: <[email protected]>
| From: Brock Allen <[email protected]>
| Subject: Re: design time support for composite controls....
| References: <[email protected]>
| Mime-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 469.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Date: Sat, 06 Aug 2005 16:10:06 -0700
| NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.comcast.net 66.30.185.175
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10309
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| You need to implement a ControlDesiger-derived class to get design time
HTML.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
|
|
| > Hi,
| > I am creating composite control which consists of there textboxes.I
| > derived
| > that composite control from WebControl, INamingContainer. I am
| > creating
| > constituent controls and adding those controls to controls collection
| > in the
| > CreateChildControls() method.
| > I was under the impression that when this composite controlled is
| > dragged
| > and dropped on web form in IDE then constituent controls are
| > automatically
| > rendered by IDE. That's not happening. In design time when i drag and
| > drop
| > this control on webform, i am seeing "ControlType:COntrolID"
| > (AOCControl:AocControl1") text. But when i run the form i see the
| > constituent
| > controls.
| > Initially i did not expose any public properties for this composite
| > control. But when i exposed some fake public properties and called
| > EnsureChildControls(); from those properties then I could see the
| > constituent
| > control only when this public property is modified.
| > Any help is appreciated.
|

|
|
 
S

scsharma

Thanks a lot Steve and Allen for responding back. One thing that's still not
clear to me is that why do i see constituent controls with same code when i
set any of the property of my composite control? If, I set any property of
this control in design time then i awalys get to get see the constituent
controls in design time. Also, i do see the constituent controls in design
time when i resize my composite control(which is same as setting the width
property of this control). After resizing if i run my code and then stop
execution, i loose the UI for constituent controls in desgin time. If i
resize my control in design time again i see the constituent controls.
 
B

Brock Allen

One other approach is to call EnsureChildControls() as the first line of
your Render method. One of your property accessors might be calling this
in the designer, and that's why you sometimes see it rendered.
 
S

scsharma

Thanks Allen but i am not using render method for my controls. Infact i am
overriding controls collection.Moreover i found out that if i put
ensurechildcontrols() in constructor of my code then i can see the
constituent controls in design time but then I run into other issues like
individual controls uniques id's not being set correctly.
 
S

scsharma

Finally i was able to get my control work that way i wanted . Here is what i
did.
1. Called ensureChildControls() as first line in the constructor of my control
2. In Controls collection, i created all my constituent controls and added
them to controls collection.
3. then I overrode the render method and after calling base.Render(..)
followed by ensureChildControls().
With above approach, i was able to see constituent controls of my composite
control with out using component designer. I haven't encountered any problem
so far. Can you guys think of any potential problem down the line.
 
B

Brock Allen

Right, but my point was that it's working sometimes in the designer because
you're doing something that causes EnsureChildControls to get called. You
then could override Render in your control, call EnsureChildControls then
call your base class' Render.
 
B

Brock Allen

The only problem is that if you have a property on your control that gets
set after CreateChildControls is called that would influence how CreateChildControls
build its collection.
 
S

Steven Cheng[MSFT]

Hi SCSharma£¬

As for your current implementation, I think its ok for your control to work
as what you expect. However, IMO, I strongly don't recommend that you did
it that way. Because in this way, you're mixing the code for design-time
togetther the logic for runtime rendering, the best pratice is to isolate
design-time support from runtime code logic as much as possible(at least ,
we should use some if..else statement in our control's code to indicate
such separation). IN additino, using ControlDesigner is the most preferred
means which perfectly isolate the design-time and runtime feature of the
control. Also, since "EnsureChildControl" or "CreateChildControls" are all
the methods used for runtime controls' constructing and rendering, we're
also not recommended to call it discretionary for design-time purpose.

Just some of my opinions. Thanks,

Steven Cheng
Microsoft Online Support

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



--------------------
| Message-ID: <[email protected]>
| From: Brock Allen <[email protected]>
| Subject: Re: design time support for composite controls....
| References: <[email protected]>
| Mime-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 469.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Date: Mon, 08 Aug 2005 10:37:53 -0700
| NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.comcast.net 66.30.185.175
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10348
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| The only problem is that if you have a property on your control that gets
| set after CreateChildControls is called that would influence how
CreateChildControls
| build its collection.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
|
|
| > Finally i was able to get my control work that way i wanted . Here is
| > what i
| > did.
| > 1. Called ensureChildControls() as first line in the constructor of my
| > control
| > 2. In Controls collection, i created all my constituent controls and
| > added
| > them to controls collection.
| > 3. then I overrode the render method and after calling base.Render(..)
| > followed by ensureChildControls().
| > With above approach, i was able to see constituent controls of my
| > composite
| > control with out using component designer. I haven't encountered any
| > problem
| > so far. Can you guys think of any potential problem down the line.
| >
| > "Brock Allen" wrote:
| >
| >> One other approach is to call EnsureChildControls() as the first line
| >> of your Render method. One of your property accessors might be
| >> calling this in the designer, and that's why you sometimes see it
| >> rendered.
| >>
| >> -Brock
| >> DevelopMentor
| >> http://staff.develop.com/ballen
| >>> Thanks a lot Steve and Allen for responding back. One thing that's
| >>> still not clear to me is that why do i see constituent controls with
| >>> same code when i set any of the property of my composite control?
| >>> If, I set any property of this control in design time then i awalys
| >>> get to get see the constituent controls in design time. Also, i do
| >>> see the constituent controls in design time when i resize my
| >>> composite control(which is same as setting the width property of
| >>> this control). After resizing if i run my code and then stop
| >>> execution, i loose the UI for constituent controls in desgin time.
| >>> If i resize my control in design time again i see the constituent
| >>> controls.
| >>>
| >>> "Steven Cheng[MSFT]" wrote:
| >>>
| >>>> Thanks for Brock's informative inputs.
| >>>>
| >>>> Hi SCSharma,
| >>>>
| >>>> The problem that VS.NET ide DISPLAY nothing for composite contorl
| >>>> is because VS.NET webform design-view by default will look for the
| >>>> WebControl's "Render" method to get the design-time HTML to
| >>>> display. Since composite control didn't use the "Render" method for
| >>>> displaying, so there will have nothing at design-view. AS Brock
| >>>> has mentioned, we can supply a custom ControlDesigner for our
| >>>> control. The ControlDesigner has a "GetDesignTimeHtml" overrideable
| >>>> function which is used to generate the html displayed at
| >>>> design-time in VS.NET ide.
| >>>>
| >>>> #Implementing a Simple Web Forms Control Designer
| >>>> http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhtmldesig
| >>>> ne rsample .asp?frame=true
| >>>>
| >>>> Hope also helps.Thanks,
| >>>>
| >>>> Steven Cheng
| >>>> Microsoft Online Support
| >>>> Get Secure! www.microsoft.com/security
| >>>> (This posting is provided "AS IS", with no warranties, and confers
| >>>> no
| >>>> rights.)
| >>>> --------------------
| >>>> | Message-ID: <[email protected]>
| >>>> | From: Brock Allen <[email protected]>
| >>>> | Subject: Re: design time support for composite controls....
| >>>> | References: <[email protected]>
| >>>> | Mime-Version: 1.0
| >>>> | Content-Transfer-Encoding: 8bit
| >>>> | Content-Type: text/plain; charset=iso-8859-1; format=flowed
| >>>> | X-Newsreader: JetBrains Omea Reader 469.1
| >>>> | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| >>>> | Date: Sat, 06 Aug 2005 16:10:06 -0700
| >>>> | NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.comcast.net
| >>>> 66.30.185.175
| >>>> | Lines: 1
| >>>> | Path:
| >>>> TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| >>>> | Xref: TK2MSFTNGXA01.phx.gbl
| >>>> microsoft.public.dotnet.framework.aspnet.webcontrols:10309
| >>>> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| >>>> |
| >>>> | You need to implement a ControlDesiger-derived class to get
| >>>> design
| >>>> time
| >>>> HTML.
| >>>> |
| >>>> | -Brock
| >>>> | DevelopMentor
| >>>> | http://staff.develop.com/ballen
| >>>> |
| >>>> |
| >>>> |
| >>>> | > Hi,
| >>>> | > I am creating composite control which consists of there
| >>>> textboxes.I
| >>>> | > derived
| >>>> | > that composite control from WebControl, INamingContainer. I am
| >>>> | > creating
| >>>> | > constituent controls and adding those controls to controls
| >>>> collection
| >>>> | > in the
| >>>> | > CreateChildControls() method.
| >>>> | > I was under the impression that when this composite controlled
| >>>> is
| >>>> | > dragged
| >>>> | > and dropped on web form in IDE then constituent controls are
| >>>> | > automatically
| >>>> | > rendered by IDE. That's not happening. In design time when i
| >>>> drag
| >>>> and
| >>>> | > drop
| >>>> | > this control on webform, i am seeing "ControlType:COntrolID"
| >>>> | > (AOCControl:AocControl1") text. But when i run the form i see
| >>>> the
| >>>> | > constituent
| >>>> | > controls.
| >>>> | > Initially i did not expose any public properties for this
| >>>> composite
| >>>> | > control. But when i exposed some fake public properties and
| >>>> called
| >>>> | > EnsureChildControls(); from those properties then I could see
| >>>> the
| >>>> | > constituent
| >>>> | > control only when this public property is modified.
| >>>> | > Any help is appreciated.
| >>>> |
| >>>> | |
|

|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top