日期验证文本框服务器控件
我正在尝试创建一个自定义服务器控件,该控件只是一个带有 AJAX asp.net MASKEDEDITEXTENDER 的文本框,以便在失去焦点时验证该控件,以确保输入了正确的日期。
到目前为止,这就是我所拥有的一切,我能够构建控件,但没有进行验证我在这里做错了什么。
namespace One_Eva_Control_Library
{
[ToolboxData("<{0}:Valid_Date_Textbox runat=server></{0}:Valid_Date_Textbox>")]
public class Valid_Date_Textbox : System.Web.UI.WebControls.TextBox
{
#region Methods
/// <summary>
/// Creates Validator
/// </summary>
/// <param name="e">Init eventArg</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
MaskedEditExtender meDateValidator = new MaskedEditExtender();
meDateValidator.ID = "dateExtender";
meDateValidator.Mask = "99/99/9999";
meDateValidator.MessageValidatorTip = true;
meDateValidator.MaskType = MaskedEditType.Date;
meDateValidator.UserDateFormat = MaskedEditUserDateFormat.DayMonthYear;
meDateValidator.CultureName = "en-GB";
MaskedEditValidator meEditValidtor = new MaskedEditValidator();
meEditValidtor.ControlExtender = meDateValidator.ID;
meEditValidtor.ControlToValidate = base.ID;
meEditValidtor.InvalidValueMessage = "Invalid Date";
meEditValidtor.Display = ValidatorDisplay.Dynamic;
meEditValidtor.TooltipMessage = "Input date in 99/99/9999 format";
meEditValidtor.InvalidValueMessage = "*";
meEditValidtor.ValidationGroup = "MKE";
}
#endregion
}
I'm trying to create a custom server control that is just a textbox with an AJAX asp.net MASKEDEDITEXTENDER to valid the control when it loses focus to ensure that a proper date has been entered.
This is all I have so far and I'm able to build the control but no validation is taking place what am I doing wrong here.
namespace One_Eva_Control_Library
{
[ToolboxData("<{0}:Valid_Date_Textbox runat=server></{0}:Valid_Date_Textbox>")]
public class Valid_Date_Textbox : System.Web.UI.WebControls.TextBox
{
#region Methods
/// <summary>
/// Creates Validator
/// </summary>
/// <param name="e">Init eventArg</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
MaskedEditExtender meDateValidator = new MaskedEditExtender();
meDateValidator.ID = "dateExtender";
meDateValidator.Mask = "99/99/9999";
meDateValidator.MessageValidatorTip = true;
meDateValidator.MaskType = MaskedEditType.Date;
meDateValidator.UserDateFormat = MaskedEditUserDateFormat.DayMonthYear;
meDateValidator.CultureName = "en-GB";
MaskedEditValidator meEditValidtor = new MaskedEditValidator();
meEditValidtor.ControlExtender = meDateValidator.ID;
meEditValidtor.ControlToValidate = base.ID;
meEditValidtor.InvalidValueMessage = "Invalid Date";
meEditValidtor.Display = ValidatorDisplay.Dynamic;
meEditValidtor.TooltipMessage = "Input date in 99/99/9999 format";
meEditValidtor.InvalidValueMessage = "*";
meEditValidtor.ValidationGroup = "MKE";
}
#endregion
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将它们添加到控件集合中。我不知道从 TextBox 继承会得到你想要的东西;我认为您可能需要继承 CompositeControl,并重写 CreateChildControls 并创建文本框和扩展器/验证器。只需确保将它们全部添加到控件集合中即可...
You need to add them to the controls collection. I don't know that inheriting from TextBox will get you what you want; I think you may need to inherit from CompositeControl, and override CreateChildControls and create the textbox, and the extender/validator. Just make sure to add all of them to the controls collection...