Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Textbox control w/ Required Val

Status
Not open for further replies.

rpeters74

Programmer
May 24, 2002
46
0
0
US
I would like to create a custom TextBox that has a RequiredFieldValidator on it. I have attempted creating such a control that Inherits from TextBox, adding a RequiredFeildValidator (using Me.Controls.Add) in CreateChildControls. I set the RequiredFeildValidator.ControlToValidate property to Me.ID. When I run I get an error stating that the ControlToValidate can not be found.

I would like to create this control Inheriting from Textbox to expose all the TextBox attributes. Is this possible?
 
Should be possible, although I think what you want to create is a composite control, or a new control that contains both the textbox and the validator.

Basically, use composition rather than inheritance.

You could either expose the control's inner text box as a property, or wrap some of the text box's properties with properties in your own control.




Greetings,
Dragonwell
 
I figured that was the an option. Inherit WebControl then have the textbox and validator created in the CreateChildControls. Just was fishing for a way to do so w/o having to expose all of the Texboxes inherent controls manually. 'preciate the response dragonwell!
 
So I went ahead an crated a control with a Textbox and a ReqFieldValidator.

I created another control that uses the above control. In the new control I want to be able to point to the Textbox in the above control as the ControlToValidate. I keep geeting the following error :

Unable to find control id 'num_txtMonth__txtTextbox' referenced by the 'ControlToValidate' property of ''.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top