Note that there are some explanatory texts on larger screens.

plurals
  1. PORequiredFieldValidators on a custom composite control
    text
    copied!<p>I have designed a custom composite control. For simplicity's sake, let's say it looks like this:</p> <pre><code>Public Class MyCustomControl Inherits CompositeControl Private _textbox As TextBox Public Property Text As String Get EnsureChildControls() Return _textbox.Text End Get Set(value As String) EnsureChildControls() _textbox.Text = value End Set End Property Protected Overrides Sub CreateChildControls() _textbox = New TextBox() With {.ID = "textbox"} Controls.Add(_textbox) End Sub </code></pre> <p>Now I am trying to allow consumers of <code>MyCustomControl</code> to use a <code>RequiredFieldValidator</code> to ensure that the inner <code>_textbox</code> is filled out when a form submits (on the client).</p> <p>What I have tried:</p> <ul> <li>Added the <code>&lt;ValidationProperty("Text")&gt;</code> to the <code>MyCustomControl</code> Class and used <code>ControlToValidate="customControlID"</code> on the <code>RequiredFieldValidator</code> (see <a href="http://support.microsoft.com/kb/310082" rel="nofollow">here</a>)</li> <li>Directly attach the validator via <code>ControlToValidate="customControlID:textbox"</code> as well as <code>ControlToValidate="customControlID_textbox"</code></li> <li>Added an <code>IsRequired</code> attribute to <code>MyCustomControl</code> which adds it's own <code>RequiredFieldValidator</code> as a child control with <code>.ControlToValidate = _textbox.ID</code></li> </ul> <p>The third approach does appear to work (there are some javascript errors that I have not yet looked into) but I would really like to get the FIRST approach working (using the <code>ValidationProperty</code> attribute).</p> <p><strong>TLDR: Is there any way to use the <code>ValidationProperty</code> attribute to achieve client-side validation on a custom composite control?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload