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
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