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. Also, feel free to checkout my egghead.io profile page for addition free and subscription lessons, collections, and courses. As always, you can reach out to me on Twitter at @elijahmanor. Thanks and have a blessed day!

Reddit