日期验证文本框服务器控件

发布于 2024-09-12 12:14:12 字数 1622 浏览 7 评论 0原文

我正在尝试创建一个自定义服务器控件,该控件只是一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-09-19 12:14:13

您需要将它们添加到控件集合中。我不知道从 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文