By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

Validator inside WebControl

P: n/a
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
Jan 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Sam" <ne**@verveeltzich.com> wrote in message
news:ne********************@news.easynet.nl...
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.

Jan 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.