开发者

ASP.NET 2.0 WebControlAdapters cannot be used on Validator controls?

I'm using a CompareValidator on a page, and I added a ControlAdapter (via browserfile) to watch all BaseVa开发者_Go百科lidator 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?


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"
            />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜