Dynamic Validation Control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Dynamic Validation Control

    I am adding several controls dynamically in a composite control. Everytime I
    add a control to the controls collection I increment an integer so I would
    guess I know the where about the control is in the control collection.
    I get the id of that control like this
    validateid = Controls(ControlCounter).id
    valrequired.ControltoValidate = validateid
    Next I add a validate control. This causes my control to throw an error
    The ControlToValidate property of '' cannot be blank.
    I have also tried to uniqueid but I then get:
    Unable to find control id 'CompControl1:_ctl2' referenced by the
    'ControlToValidate' property of

    Can anyone point me in the right direction, Chris.


    Chris Kennedy Guest

  2. Similar Questions and Discussions

    1. Dynamic validation with JS, RegEx, and CF
      I need to build a reusable complex form validator and was thinking of storing the validation logic (RegEx expressions) in the database for each...
    2. Dynamic Validation of Required Fields
      I am currently using a standard HTML form in which a user must enter certain data (required). The form has 2 submit buttons, 1 of which changes the...
    3. dynamic form validation
      I have a form with some dynamic elements in it. The code is below It is a self assessment and the user must make some selections. The first part...
    4. Syntax for dynamic validation control
      I want to assign a validation control dynamically. How do I tell it what control to validate via the controls collection. It seems to want a string...
    5. only custom validation control does server side validation?
      On a CustomValidator you have to provide the validation code because otherwise it doesn't know what to do for the validation. Other validator...
  3. #2

    Default Re: Dynamic Validation Control

    Quote Originally Posted by Chris Kennedy View Post
    I am adding several controls dynamically in a composite control. Everytime I
    add a control to the controls collection I increment an integer so I would
    guess I know the where about the control is in the control collection.
    I get the id of that control like this
    validateid = Controls(ControlCounter).id
    valrequired.ControltoValidate = validateid
    Next I add a validate control. This causes my control to throw an error
    The ControlToValidate property of '' cannot be blank.
    I have also tried to uniqueid but I then get:
    Unable to find control id 'CompControl1:_ctl2' referenced by the
    'ControlToValidate' property of

    Can anyone point me in the right direction, Chris.
    When you create the target control, set the id to some value, then you use the same value to set the ControltoValidate of the validator.
    e.g.

    TextBox txtBox = new TextBox();
    txtBox.ID = "txt_box_target";
    RequiredFieldValidator rfv = new RequiredFieldValidator();
    rfv.ControlToValidate = txtBox.ID;
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139