0

我有一个RadEditor,我正在尝试添加一个CustomValidator,如下所示:

protected override void OnInit(EventArgs e)
{
    var validator = new CustomValidator();
    validator.CssClass = "validator-error";
    validator.Display = ValidatorDisplay.Dynamic;
    validator.ControlToValidate = ".";
    validator.Text = "You've exceeded the maximum allowed length for this field";
    validator.ClientValidationFunction = "radEditorCheckLength";

    this.Controls.Add(validator);

    base.OnInit(e);
}

效果很好,但是当它呈现时,验证器实际上是RadEditor. 如何让它出现在RadEditor元素之前?

在此处输入图像描述

4

1 回答 1

1

这是一个彻头彻尾的黑客攻击。它有效吗?

protected override void Render(HtmlTextWriter writer)
{
    this.validator.RenderControl(writer);
    this.validator.Visible = false;
    base.Render(writer);
    this.validator.Visible = true;
}

您需要将您的存储CustomValidator在一个字段中:

private CustomValidator validator;

protected override void OnInit(EventArgs e)
{
    this.validator = new CustomValidator();
    // ...
}

(我RadEditor在 Reflector 中进行了反汇编,但我没有看到一种简单的修改方法RenderChildren来跳过渲染验证器。)

于 2012-04-06T18:07:40.017 回答