Which way to build control?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngarchitecture' list.


Adam Monsky
-- Moved from [aspngcontrolscs] to [aspngarchitecture] by Tony Stark <Click here to reveal e-mail address> --

I'm sure that I want to create a server control, however, I'm not sure if =
I need a composite control or to inherit and extend and existing control. =
I want to create an enhanced textbox control that always creates a custom =
validator control along with it. The validator would provide various =
validation functionality that our business requires, and would be =
standardized for all instances of the custom textbox control. We'd like =
to simply code the validator once, then have it look at the text's =
properties that it's associated with so it knows which validation logic to =
use. This would allow us to drop many custom textbox controls on a web =
form, and set the various custom textbox properties to drive the validator.=
Ideally, we don't even want to worry about dropping a validator and =
hooking it up. We'd like the custom control to handle this automatically.

If I create a composite control, then basically I'd be wrapping a custom =
server control around a custom textbox and a custom validator. In this =
scenario, most of the properties of the composite control would really =
need to be mapped to the textbox control, such as height, width, color, =
font, text, alignment, etc. Of course, these properties are already =
available on the custom textbox control, but I'd have to map them from the =
composite control to the custom textbox control using property get/set =
statements, right? Is there anyway to make the custom textbox control's =
(which is a child control of the composite control) properties map to the =
composite control's properties without coding them all individually? =
Also, wouldn't I be responsible for creating the design time support in =
the composite control, so that the property sheet (and it's various type =
converters?) is available to the developer within the VS.NET IDE? Again, =
if most of the custom textbox properties could be used, that would be =
ideal.=20

The other approach I see would be to create a custom textbox control that =
inherits from the standard textbox control. I could extend the control =
without too much difficulty to support additional properties for our =
business use. However, how to I cause a custom validator to get created =
for every instance of the custom textbox control? Would I simply create =
the custom validator and add it to the page's controls in the OnInit =
method of the custom textbox control? If so, how would this handle =
postbacks? Actually, does the validator need to handle postbacks? All of =
the logic in the custom validator class would effectively be static and =
the same for any instance of the validator/textbox combination.

Does anyone have any insight as to which way would be better and avoid the =
most pitfalls? I've read articles and reviewed source that shows about =
how to create a custom validator, and ones that show a custom server =
control. However, I've not seen discussions or examples of how to =
integrate the a custom validator and a textbox into a custom server =
control. Any pointers/links/samples that could point me in the right =
direction would be appreciated.

Reply to this message...
 
    
Andy Smith
my first instinct is "Composite Control"...

but I think you'd get away with less coding if you subclass TextBox and =
see if you can add the validator to the Controls collection of the =
TextBox. not sure you'll get flexibility you want from this method tho.

also, you might want to go to GotDotNet.com and find a little tool =
written by MS in the "User Samples" area which helps you create =
subclasses and containing classes. something like "Derive Class Tool".

__
Andy Smith
Keyboard Jockey #3a7-2.78.1

[Original message clipped]

Reply to this message...
 
 
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.TextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com