Custom Validators for Composite Controls
1 min read

I have created several custom composite controls (containing multiple input fields) and validators for our website at work.

I needed the SetFocusOnError property to work on my custom validators, but it didn't work by default.

I started to dig through ASP.NET's JavaScript code and found that if my custom composite control was enclosed in a table tag (instead of the default div tag) that the JavaScript would search the table tag for input controls.

The following code will change the default enclosed tag from a div to a table.

public class LengthEditor : CompositeControl
{
    protected override HtmlTextWriterTag TagKey
    {
        get { return HtmlTextWriterTag.Table; }
    }
}

Edit post on GitHub


Walking on Water
Safari on Windows