Last post Feb 10, 2009 03:13 PM by Mike Bell
Feb 05, 2009 03:29 PM|rkolsky|LINK
Hi, I am developing a custom server control to enhance the built in validator controls for ASP.NET. To keep things simple, I want to check more than one type of value in one control.
Currently I have 3 values I want to set for each type of error checking routine to be performed. Each routine has a property called enabled, errormessage, and regularexpression. I could list these out as separate properties that can be set in the control tag
itself, but it seems silly to have something like ValidIntegerEnabled, ValidIntegerMessage, ValidDecimalEnabled, ValidDecimalMessage and so forth when I can just create a custom class with the three properties and make each property of that class type (whcih
is what I did).
I have the control working fine, however, I have to set these properties by code (e.g. CustomValidator.ValidateIntegers.Enabled = true;). I would prefer to set these declaratively inbetween the opening and closing tags as an alternative to setting it by code.
I also plan to enhance the control to allow templates to customize the exact look and feel of the error so this needs to work with templated controls as well.
I explored the posibility of allowing a collection to be added declaratively and then parsing that collection into the correct properties but from what I was able to learn you can either do a collection based control or a template control, but the two are mutually
Anyone know if what I want to do is possible and/or how to do it?
Feb 05, 2009 11:52 PM|Mike Bell|LINK
You should be getting these properties in the designer. Do you have them marked with any attributes? Are they public?
Feb 06, 2009 09:06 AM|rkolsky|LINK
I don't have any attributes set to these properties yet. I'm not sure if properties are what I need or something else, so before I do too much work setting up all the attributes for all my properties (and I have dozens) I want to make sure that what I want
to do is even possible. If not then I will just switch them up so that each validation routine has three properties like ValidIntegerEnabled ValidIntegerMessage etc... Here is a sample of what I would like to be able to do in the aspx page. (Theoretical Syntax)
<sa:CustomValidator runat="server" id="CustomValidator1">
<sa:ValidInteger Enabled="True" Message="Some Message">
<sa:ValidDate Enabled="True" Message="Some Message">
<asp:Label ....>Some Text</asp:Label>
Feb 06, 2009 09:22 AM|Mike Bell|LINK
So the ValidInteger (which is it's own class, correct?) property within your CustomValidator class would look something like:
public ValidInteger MyValidInteger
Feb 10, 2009 01:04 PM|rkolsky|LINK
Hey Mike, Thanks for the response. This worked out mostly the way I wanted. I can now set inline in the control declaration properties such as
Do you know if it is possible to actualy be able to have separate tags within the control as well? For example, this is how I would currently write the control
<sa:CustomValidator runat="server" id="someid" ValidateInteger-Enabled="true"></sa:CustomValidator>
Ideally I would like to do something like this as well
<sa:CustomValidator runat="server" id="someid">
<ValidateInteger enabled="true" />
Thanks again for your help, even if the above is not possible this will still work out for me.
Feb 10, 2009 03:13 PM|Mike Bell|LINK
Yeah it's possible. Along with:
Your main control class will need to be preceded with these attributes:
That should do the trick.