我们如何将正则表达式添加到从TextBox继承的customcontrol中. [英] How can we add a regex to the customcontrol inherited from TextBox.
本文介绍了我们如何将正则表达式添加到从TextBox继承的customcontrol中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public override void RenderBeginTag(HtmlTextWriter writer)
{
// Set the maxlength and the min length using regex for multiline textboxes...
RegularExpressionValidator rev = new RegularExpressionValidator { ControlToValidate = ClientID, ValidationExpression = @"^[\s\S]{" + MinLength + "," + (MaxLength == 0 ? 1000000 : MaxLength) + "}$", ErrorMessage = "Please enter a valid length." };
this.Parent.Controls.Add(rev);
// The prev line is giving error:
// Collection was modified; enumeration operation may not execute.
// Even tried the above in Onprerender also, but no luck.
base.RenderBeginTag(writer);
}
推荐答案
",ErrorMessage = }; 此 .Parent.Controls.Add(rev); // 上一行显示错误: // 集合已修改;枚举操作可能无法执行. // 甚至在Onprerender中也尝试了上述方法,但是没有运气. 基本 .RenderBeginTag(writer); }
", ErrorMessage = "Please enter a valid length." }; this.Parent.Controls.Add(rev); // The prev line is giving error: // Collection was modified; enumeration operation may not execute. // Even tried the above in Onprerender also, but no luck. base.RenderBeginTag(writer); }
您需要用户控件,而不是自定义控件.您正在做的事情有点骇人听闻,您是在使用错误的工具来完成工作.
You want a user control, not a custom control. What you''re doing is a bit of a hack, you''re using the wrong tools for the job.
这篇关于我们如何将正则表达式添加到从TextBox继承的customcontrol中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文