Validator inside WebControl

S

Sam

Hi all,

Why can't i create a validatorControl as a child of the control to validate?
It doesn't give any errors, but it just won't work (it's not validating).

The reason why i want this is that i'm creating a repository of
WebControls extended/inherited with my own code for repetative use.
For example, i have a: Class CreationDate inherits TextBox
I offcourse want a validator to check is really a date was entered into
the textbox.
I use this custom WebControl on multiple pages.
In those pages i only want to code:
<myRepository:CreationDate runat="server" />
I do not want to code a <asp:rangeValidator> on every page. That should
be handled by the <myRepository:CreationDate> tag itself.

I've tried:
--------------------
Public Class CreationDate inherits TextBox
Sub new
dim validator as new RangeValidator
'setting validator properties
me.controls.add(validator)
End Sub
End Class
--------------------
This just doesn't work. no errors, but also no validation.

So i tried:
--------------------
Public Class CreationDate inherits TextBox
Sub onInit/onLoad
dim validator as new RangeValidator
'setting validator properties
me.page.controls.add(validator)
End Sub
End Class
--------------------
This gave an error that i'm not allowed to add controls to the controll
collection (of the page) while in onInit/onLoad/onPreRender mode.
The page is currently in PreRender mode (in a non postback situation)
when this object goes through it's events.
I should mention that this WebControl is in a (CompiledBindable)Template
which is instantiated in the CreateChildControls of it's container.
(but this CreateChildControls is created in the onLoad event i believe).

I've also tried.
--------------------
me.parent.controls.add(validator)
--------------------
But this also didn't work.

So could anyone please tell me how i can add a validator from within the
control(ToValidate) itself.

I'm just don't know anymore (and sometime can get really frustrated on
"the microsoft way" of doing things)

I hope somebody has a solution for me, otherwise this repository is
quite doomed.

Regards,

Sam
 
J

Jeff Johnson [MVP: VB]

Class CreationDate inherits TextBox

This is a VB "classic" newsgroup. Questions about VB.NET (including VB 2005,
which has dropped .NET from its name) are off-topic here.

Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top