Custom Validators for Composite Controls

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; }
}
}

If you enjoyed this post, please consider sharing it with others via the following Twitter or Reddit buttons. I also have a YouTube Channel with free web development videos that you are welcome to watch and/or subscribe. As always, you can reach out to me on Twitter at @elijahmanor. Thanks and have a blessed day!

Reddit