Wednesday, June 13, 2007

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

2 comments:

  1. Anonymous12:07 AM

    http://poppinmycollar.ytmnd.com/

    ReplyDelete
  2. Anonymous9:44 AM

    I have had to get Validators to work with my CompositeControls recently. One of the issues I had was getting the ControlToValidate pointing at an ID of a Control that would accept focus and hold the Value. Here is where I got to
    creating validatable compositecontrols

    The outstanding issue i have is how get the SetFocusOnError thing to work with Firefox. I cannot get this to work even with the standard Validators

    Have you got this working

    ReplyDelete