我已经面临以下问题并与之抗争了将近 2 天。我有以下代码。
protected override void Render(HtmlTextWriter writer)
{
string controlOutput;
string validatorOutput;
string allOutput;
StringWriter controlStringWriter = new StringWriter();
HtmlTextWriter controlHtmlWriter = new HtmlTextWriter(controlStringWriter);
StringWriter validatorsStringWriter = new StringWriter();
HtmlTextWriter validatorsHtmlWriter = new HtmlTextWriter(validatorsStringWriter);
base.Render(controlHtmlWriter);
controlOutput = controlStringWriter.ToString();
this.renderValidators(validatorsHtmlWriter);
validatorOutput = validatorsStringWriter.ToString();
allOutput = String.Format("{0} {1}", controlOutput, validatorOutput);
writer.Write(allOutput);
}
renderValidators 函数是:
private void renderValidators(HtmlTextWriter writer)
{
foreach (BaseValidator validator in this.ValidatorsCollection)
{
validator.RenderControl(writer);
}
}
渲染函数返回一个空字符串。集合中的 Validator 的 Visible 属性设置为 true。
我在 OnInit 函数中添加验证器。在第一次渲染期间 validator.RenderControl(writer); 返回一个空字符串,回发后它开始返回一个 html 输入......
也许有人遇到过这样的问题???