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

时间:2010-08-03 18:50:51

标签: c# asp.net custom-server-controls

我正在尝试创建一个自定义服务器控件,它只是一个带有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
    }

1 个答案:

答案 0 :(得分:0)

您需要将它们添加到控件集合中。我不知道继承TextBox会得到你想要的东西;我想你可能需要从CompositeControl继承,并覆盖CreateChildControls并创建文本框和扩展器/验证器。只需确保将所有这些内容添加到控件集合中......