![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
1. A control inherited from webControl that overrides CreateChildControls to |
|
2. A control inherited from WebControl. It has controls added to hierachy during load. It overrides Render and explicitely loops thru all its |
|
3. A control inherited from TextBox. It has controls added to hierachy during load. It overrides Render and explicitely loops thru all its |
#3
| |||
| |||
|
|
Hi TS, 1. A control inherited from webControl that overrides CreateChildControls to add all of its controls to hierarchy. No render methods overridden. The controls are rendered in the order i added them to control hierarchy This is the recommended approach to create a composite control that consists of several child controls. Actually in ASP.NET 2.0 we have a dedicated parent class to let you inherit from: CompositeControl. #A Crash Course on ASP.NET Control Development: Building Composite Controls http://msdn2.microsoft.com/en-us/library/aa479016.aspx 2. A control inherited from WebControl. It has controls added to hierachy during load. It overrides Render and explicitely loops thru all its controls and renders them (ReqFieldValidators, etc) 3. A control inherited from TextBox. It has controls added to hierachy during load. It overrides Render and explicitely loops thru all its controls and renders them (ReqFieldValidators, etc) I believe you're referring to a similar approach as this article shows: #Building an ASP.NET custom web control: a textbox and validator in one - The Code Project - ASP.NET http://www.codeproject.com/aspnet/te...hvalidator.asp Please note the RenderChildren is called by Render by default in class Control. However, a control could choose to override the Render method and not call base.Render() at all. In this case, TextBox's Render is not calling RenderChildren. In summary, this approach is NOT recommended to create a composite control. Actually the code in the CodeProject article has a bug: OnInit isn't called during design-time and the RequiredFieldValidator instance is null in Render. Hope this helps. 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. |
#4
| |||
| |||
|
|
i have tested the theory that RenderChildren will be called by base's implementation of Render and it doesn't seem to work. What i want to do is have a normal textbox that adds a ReqFieldValidator. Though in display only mode i want the textbox to render as a label and don't have the ReqFieldValidator render at all. So I've included what i'm doing below. When i set a breakpoint at RenderChildren (during edit mode) it is not hit even though i step thru the code and it calls base.Render in my Render override. Is the reason for this because the TextBox is not supposed to be used as a container control and since it doesn't implement INamingContainer? thanks protected override void Render(System.Web.UI.HtmlTextWriter writer){ if (ReadOnly){ Label label = new Label(); label.CssClass = CssClass; label.Text = Text.Replace("\n", "<BR/>"); label.ID = this.ClientID; label.RenderControl(writer); Page.ClientScript.RegisterHiddenField(ID, Text); } else{ base.Render(writer); } } protected override void CreateChildControls(){ RequiredFieldValidator validator = new RequiredFieldValidator(); validator.ID = String.Format("RFV{0}", ID); validator.Display = ValidatorDisplay.Dynamic; validator.ControlToValidate = ID.ToString(); validator.Label = ValidatorLabel; validator.SetFocusOnError = SetFocusOnError; validator.ValidationGroup = ValidationGroup; Controls.Add(validator); base.CreateChildControls(); } protected override void RenderChildren(HtmlTextWriter writer){ base.RenderChildren(writer); } ""Walter Wang [MSFT]"" <wawang (AT) online (DOT) microsoft.com> wrote in message news:Xk8Llf%23KIHA.5204 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl... Hi TS, 1. A control inherited from webControl that overrides CreateChildControls to add all of its controls to hierarchy. No render methods overridden. The controls are rendered in the order i added them to control hierarchy This is the recommended approach to create a composite control that consists of several child controls. Actually in ASP.NET 2.0 we have a dedicated parent class to let you inherit from: CompositeControl. #A Crash Course on ASP.NET Control Development: Building Composite Controls http://msdn2.microsoft.com/en-us/library/aa479016.aspx 2. A control inherited from WebControl. It has controls added to hierachy during load. It overrides Render and explicitely loops thru all its controls and renders them (ReqFieldValidators, etc) 3. A control inherited from TextBox. It has controls added to hierachy during load. It overrides Render and explicitely loops thru all its controls and renders them (ReqFieldValidators, etc) I believe you're referring to a similar approach as this article shows: #Building an ASP.NET custom web control: a textbox and validator in one - The Code Project - ASP.NET http://www.codeproject.com/aspnet/te...hvalidator.asp Please note the RenderChildren is called by Render by default in class Control. However, a control could choose to override the Render method and not call base.Render() at all. In this case, TextBox's Render is not calling RenderChildren. In summary, this approach is NOT recommended to create a composite control. Actually the code in the CodeProject article has a bug: OnInit isn't called during design-time and the RequiredFieldValidator instance is null in Render. Hope this helps. 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
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |