views:

11

answers:

1

I'm using a CompareValidator on a page, and I added a ControlAdapter (via browserfile) to watch all BaseValidator classes (and their derivatives). My ControlAdapter does nothing - overrides no methods, currently. The validator writes the span tag, it's id and style, but nothing else - no error message, no javascript. Any ideas why?

A: 

Whoops; wrote too soon. The answer is: the standard WebControlAdapter overrides the Render() method - which is where the processing of the Validator happens. The solution is to subclass the abstract System.Web.UI.Adapters.ControlAdapter and create your own Adapter (which can actually be empty).

public class ValidatorAdapter : System.Web.UI.Adapters.ControlAdapter { }
public class FieldError : ValidatorAdapter
{
    protected void RenderBeginTag(HtmlTextWriter writer)
    {
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "fieldError");
        writer.RenderBeginTag(HtmlTextWriterTag.Div);
    }
    protected override void Render(HtmlTextWriter writer)
    {
        RenderBeginTag(writer);
        base.Render(writer);
        RenderEndTag(writer);
    }
    protected void RenderEndTag(HtmlTextWriter writer)
    {
        writer.RenderEndTag();
    }
}

and, add this to the of the browse file:

        <adapter controlType="System.Web.UI.WebControls.BaseValidator"
            adapterType="UI.ControlAdapters.FieldError"
            />
end-user