![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
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. |
#5
| |||
| |||
|
|
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. |
#6
| |||
| |||
|
|
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. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
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. |
#9
| |||
| |||
|
|
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. |
#10
| |||
| |||
|
|
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. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |