HighTechTalks DotNet Forums  

Building a rendered control with child controls

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Building a rendered control with child controls in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
TS
 
Posts: n/a

Default Building a rendered control with child controls - 04-26-2007 , 12:37 PM






I am building a control that inherits from Textbox. I am adding a required
field validator to the controls. should i be inheriting from WebControl
instead and overriding CreateChildControls?

Why or why not?

thanks



Reply With Quote
  #2  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 04-26-2007 , 12:53 PM






Oh yeah, and those controls are added during load and they are rendered in
Render (actually this isnt my code). I guess they are building a composite
control as a rendered control.

what benefits do you get when you override a control (rendered control)
versus a composite control (say you had only a single control you wanted to
display in a custom control, would benefits do you get when you make it a
rendered control versus a composite control?)

thanks again!

"TS" <manofsteele1 (AT) nospam (DOT) nospam> wrote

Quote:
I am building a control that inherits from Textbox. I am adding a required
field validator to the controls. should i be inheriting from WebControl
instead and overriding CreateChildControls?

Why or why not?

thanks





Reply With Quote
  #3  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default Re: Building a rendered control with child controls - 04-27-2007 , 03:07 AM



Hi TS,

I think a TextBox with validation is a special case here since you could
either use a composite control or implements IValidator interface to add
validation function to a class
(http://www.codeproject.com/aspnet/se...ngtextbox.asp).

For a composite control with a single constituent control, the difference
between composition and inheritance would be:

1) A composite control will need to implement INamingContainer, which will
create a naming container for the children.

2) Inherited control still has public methods/properties for your user,
while a composite control will have to expose the only child to let your
user use the properties/methods directly.

Other than these, I believe other things such as performance will not be
affected.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #4  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 04-27-2007 , 11:15 AM



thanks walter

"Walter Wang [MSFT]" <wawang (AT) online (DOT) microsoft.com> wrote

Quote:
Hi TS,

I think a TextBox with validation is a special case here since you could
either use a composite control or implements IValidator interface to add
validation function to a class
(http://www.codeproject.com/aspnet/se...ngtextbox.asp).

For a composite control with a single constituent control, the difference
between composition and inheritance would be:

1) A composite control will need to implement INamingContainer, which will
create a naming container for the children.

2) Inherited control still has public methods/properties for your user,
while a composite control will have to expose the only child to let your
user use the properties/methods directly.

Other than these, I believe other things such as performance will not be
affected.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Reply With Quote
  #5  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 05-16-2007 , 04:56 PM



Some of these controls i see like i said just render themselves and any
other controls in their controls collection. They add their validation
controls as controls of the control and then render them separately. Using
this scenario for DropdownList i have a problem that errors out: "does not
allow child controls". the control is inherited from dropdownlist and so it
won't work like the textbox control.

How can i get it to work while still keeping it as a rendered (inherited)
control?

since i get this "does not allow child controls", I've tried to add the
validation control to the control's parent.controls and the control's
page.controls collection to get around it but i then get "The control
collection cannot be modified during DataBind, Init, Load, PreRender or
Unload phases", so I am kinda stuck.

If i just simply render the control instead of add it to the control
hierarchy, it won't validate correctly though it is in the html source.

thanks


"Walter Wang [MSFT]" <wawang (AT) online (DOT) microsoft.com> wrote

Quote:
Hi TS,

I think a TextBox with validation is a special case here since you could
either use a composite control or implements IValidator interface to add
validation function to a class
(http://www.codeproject.com/aspnet/se...ngtextbox.asp).

For a composite control with a single constituent control, the difference
between composition and inheritance would be:

1) A composite control will need to implement INamingContainer, which will
create a naming container for the children.

2) Inherited control still has public methods/properties for your user,
while a composite control will have to expose the only child to let your
user use the properties/methods directly.

Other than these, I believe other things such as performance will not be
affected.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Reply With Quote
  #6  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 05-16-2007 , 04:59 PM



note that this validator is not getting added to the javascript variable
Page_Validators

"TS" <manofsteele1 (AT) nospam (DOT) nospam> wrote

Quote:
Some of these controls i see like i said just render themselves and any
other controls in their controls collection. They add their validation
controls as controls of the control and then render them separately. Using
this scenario for DropdownList i have a problem that errors out: "does not
allow child controls". the control is inherited from dropdownlist and so
it
won't work like the textbox control.

How can i get it to work while still keeping it as a rendered (inherited)
control?

since i get this "does not allow child controls", I've tried to add the
validation control to the control's parent.controls and the control's
page.controls collection to get around it but i then get "The control
collection cannot be modified during DataBind, Init, Load, PreRender or
Unload phases", so I am kinda stuck.

If i just simply render the control instead of add it to the control
hierarchy, it won't validate correctly though it is in the html source.

thanks


"Walter Wang [MSFT]" <wawang (AT) online (DOT) microsoft.com> wrote in message
news:Un8f$qJiHHA.4332 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Hi TS,

I think a TextBox with validation is a special case here since you could
either use a composite control or implements IValidator interface to add
validation function to a class
(http://www.codeproject.com/aspnet/se...ngtextbox.asp).

For a composite control with a single constituent control, the
difference
between composition and inheritance would be:

1) A composite control will need to implement INamingContainer, which
will
create a naming container for the children.

2) Inherited control still has public methods/properties for your user,
while a composite control will have to expose the only child to let your
user use the properties/methods directly.

Other than these, I believe other things such as performance will not be
affected.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.






Reply With Quote
  #7  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default Re: Building a rendered control with child controls - 05-17-2007 , 08:03 AM



Hi TS,

If you use the "inherited control" approach, you cannot use existing
validator controls, you have to implement IValiator interface yourself, as
http://www.codeproject.com/aspnet/se...ingtextbox.asp described.

If you want to use the existing validator controls, you will have to use
the "composite control" approach.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #8  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 05-17-2007 , 12:01 PM



OK, i can do the IValidator and i add it to Page.Validators on OnInit, but
no validation control are added to the page hierarchy and Page_validators in
js doesn't contain it. The project framework i'm using relies on the
validation control to be in this Page_Validators array for custom client
side validation.

Also, i guess i would have to manually code all the things the validation
controls do by default? How would i handle .Display =
ValidatorDisplay.Dynamic and .ValidationGroup = "xxxx"

While working on the dropdownlist i noticed i couldn't change (add controls
to) the control hierarchy. i'm wondering if there is any time in the page's
lifecycle that i could add controls to the control hierarchy - maybe check
if any controls implement IValidator and if so then create regular validator
and add to hierarchy.

thanks

"Walter Wang [MSFT]" <wawang (AT) online (DOT) microsoft.com> wrote

Quote:
Hi TS,

If you use the "inherited control" approach, you cannot use existing
validator controls, you have to implement IValiator interface yourself, as
http://www.codeproject.com/aspnet/se...ingtextbox.asp described.

If you want to use the existing validator controls, you will have to use
the "composite control" approach.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Reply With Quote
  #9  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 05-17-2007 , 12:02 PM



also if i kept the IValidator interface, i noticed i had to call .Validate()
myself - i figured the .net framework would call this automatically, but it
didn't.

thanks again walter

"Walter Wang [MSFT]" <wawang (AT) online (DOT) microsoft.com> wrote

Quote:
Hi TS,

If you use the "inherited control" approach, you cannot use existing
validator controls, you have to implement IValiator interface yourself, as
http://www.codeproject.com/aspnet/se...ingtextbox.asp described.

If you want to use the existing validator controls, you will have to use
the "composite control" approach.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Reply With Quote
  #10  
Old   
TS
 
Posts: n/a

Default Re: Building a rendered control with child controls - 05-17-2007 , 07:02 PM



ok, i guess i'm going to have to either have my control implementing
IValidator create a real validator so it goes into Page_Validators, or
abandon this and put as a separate control on page. Any ideas

"TS" <manofsteele1 (AT) nospam (DOT) nospam> wrote

Quote:
OK, i can do the IValidator and i add it to Page.Validators on OnInit, but
no validation control are added to the page hierarchy and Page_validators
in
js doesn't contain it. The project framework i'm using relies on the
validation control to be in this Page_Validators array for custom client
side validation.

Also, i guess i would have to manually code all the things the validation
controls do by default? How would i handle .Display =
ValidatorDisplay.Dynamic and .ValidationGroup = "xxxx"

While working on the dropdownlist i noticed i couldn't change (add
controls
to) the control hierarchy. i'm wondering if there is any time in the
page's
lifecycle that i could add controls to the control hierarchy - maybe check
if any controls implement IValidator and if so then create regular
validator
and add to hierarchy.

thanks

"Walter Wang [MSFT]" <wawang (AT) online (DOT) microsoft.com> wrote in message
news:Nqj6jtHmHHA.4032 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Hi TS,

If you use the "inherited control" approach, you cannot use existing
validator controls, you have to implement IValiator interface yourself,
as
http://www.codeproject.com/aspnet/se...ingtextbox.asp described.

If you want to use the existing validator controls, you will have to use
the "composite control" approach.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.