Last post Oct 12, 2007 06:24 PM by viscious
Oct 11, 2007 12:50 PM|justinlearning|LINK
I originally wrote a RequiredTextbox control which has built-in validation as a custom control subclassed from a TextBox. The problem is, from everything I've read, having a validator being rendered in such a control is apparently a pain...something about
the naming container not working correctly. I've not been able to find specific information on what the problem is, though. Can someone walk me through what exactly is the technical problem with having a textbox subclass that renders its own validator?
Oct 12, 2007 06:24 PM|viscious|LINK
There are two problems.
1.Textbox inherits from WebControl. Webcontrol does not implement INamingContainer. Therefore, if you were to place multiple RequiredTextBoxes in the same page, its possible that the RequiredFieldValidators would have ID conflicts. However there is nothing
stoping you from Implementing INamingContainer yourself, so that really isn't a problem.
2. In the WebControl base class, the render method Calls , RenderContents(), Which calls the Control Base Class Render(), which in turn Calls RenderChildren() Which in turn will render all of the child controls. However The TextBox overrites Render() of
WebControl. In TextBox version of Render, all it does is render the textbox. It bypasses all of the functionality that would allows the child controls to be rendered. So you have to manually call this functionality. Not exactly a good design pattern.