views:

15

answers:

1

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
    }
A: 

Hey,

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...

Brian