Custom Control Property as Attribute as well as inner property RRS feed

  • Question

  • User1648407555 posted

    I am developing a custom control.
    Markup should look like

         <ppl:PplValidator ID="V1" runat="server">
                <ppl:ControlToValidate ControlID="txtClientLastName" >
                    <ValidationRule Required="true" Min="3" />
                 <ppl:ControlToValidate ControlID="txtClientLastName" ValidationRule="Rule1" >

    So the Validation Rule can either be detailed rule or just name of instance of Validation Rule class. This rule name can be specified either thro' client or server side. Or it can be detailed as well.

    The code I have developed so far is

        public sealed class PplValidator : WebControl

             public List<ControlToValidate> controlsToValidate;

            public PplValidator()
                Validate = true;
                ValidateClient = true;
                ValidateServer = true;

            #region Properties

            public bool Validate { get; set; }

            public bool ValidateClient { get; set; }

            public bool ValidateServer { get; set; }

            public List<ControlToValidate> ControlsToValidate
                    if (controlsToValidate == null)
                        controlsToValidate = new List<ControlToValidate>();
                    return controlsToValidate;


            protected override void OnInit(EventArgs e)
                base.DataBind(); //ensure databinding if any by using control.databind

            protected override void Render(System.Web.UI.HtmlTextWriter writer)

         public class ControlToValidate
            public ControlToValidate()

            public string ControlID { get; set; }

            public ValidationRule ValidationRule { get; set; }


         public class ValidationRule
            public int MinChar { get; set; }

            public int MaxChar { get; set; }

            public bool Required { get; set; }

            public string Regex { get; set; }

            public InputType InputType { get; set; }

        public enum InputType

    How do I achieve it?

    Tuesday, April 10, 2012 5:00 AM

All replies

  • User-1488931086 posted

    Is there anything wrong???

    Wednesday, April 11, 2012 9:21 PM
  • User1648407555 posted

    Currently ValidationRulepnly acts as inner property.

    I want use it as InnerProperty or Attribute (No both at same time) ; how do I ?

    Or is there any other way or design by which I can allow user to specify name of complex property or indivisual premitive data types properties inside the complex property.

    Thursday, April 12, 2012 4:00 AM