/*************.ascx page*********************/

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:TextBox ID="txtDate" runat="server" MaxLength="11"></asp:TextBox>
<ajax:CalendarExtender ID="clndrDate" runat="server" TargetControlID="txtDate" Format="MM/dd/yyyy"
    CssClass="MyCalendar">
</ajax:CalendarExtender>
<div class="mandatory">
<asp:RequiredFieldValidator ID="reqUCDate" runat="server"
    ControlToValidate="txtDate" Display="Dynamic" SetFocusOnError="true"
    ErrorMessage="please select date" Text="*"></asp:RequiredFieldValidator>
<asp:RangeValidator
    ID="rangeUCDate"
    runat="server"
    SetFocusOnError="true"
    ControlToValidate="txtDate"
    ErrorMessage="Please enter valid date"
    Type="Date" Display="Dynamic"
    Enabled="false" />
</div>
<input id="txtCurrDate" type="hidden" value="<%=DateTime.Now.AddHours(20).ToString("MM/dd/yyyy") %>"/>
<asp:TextBox ID="txtTempDate" Visible="false" runat="server" MaxLength="11"></asp:TextBox>   




/*************.                  Code Behind Page           *********************/
/// <summary>
    /// This Control is use for Date Textbox with Calender control on page
    /// For this control use on page some of functions are created in javascript for validation
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //DateRequired = false;
        }
    }

    #region Variable

    private string date;

    #endregion

    #region Property
    /// <summary>
    /// This Property use for get and set date in dd MMM yyyy format
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    public string Date
    {
        get
        {
            date = txtDate.Text;
            return date;

        }
        set
        {
            date = value;
            if (date != string.Empty)
            {
                txtDate.Text = Convert.ToDateTime(date).ToString("MM/dd/yyyy");
            }
            else
            {
                txtDate.Text = "";
            }
        }

    }

    /// <summary>
    /// This Property is used to set width of data control
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    public int DateControlWidth
    {
        set
        {
            txtDate.Width = value;
        }
    }

    /// <summary>
    /// This Property is used to set height of date control
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    public int DateControlHeight
    {
        set
        {
            txtDate.Height = value;
        }
    }

    /// <summary>
    /// This Property is used to make date cotrol read only
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    public bool DateControlReadOnly
    {
        set
        {
            txtDate.ReadOnly = value;
            clndrDate.TargetControlID = "txtTempDate";
        }
        get
        {
            return txtDate.ReadOnly;
        }
    }

    /// <summary>
    /// This property used to make date mandatory
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    public bool DateRequired
    {
        set
        {
            reqUCDate.Enabled = value;
        }
    }

    public string ValidationGroup
    {
        set
        {
            reqUCDate.ValidationGroup = value;
            rangeUCDate.ValidationGroup = value;
        }
    }

    #endregion

    #region Methods
    /// <summary>
    /// Used to set maximum date
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    /// <param name="dt"></param>
    public void DateMaximum(DateTime dt)
    {
        rangeUCDate.Enabled = true;
        rangeUCDate.MaximumValue = dt.ToString("MM/dd/yyyy");
        rangeUCDate.MinimumValue = new DateTime(1600, 01, 01).ToString("MM/dd/yyyy");
    }

    /// <summary>
    /// Used to set minimum date
    /// </summary>
    /// <CreatedBy>Khushant Dhingra</CreatedBy>
    /// <CreatedDate>20/may/2011</CreatedDate>
    /// <param name="dt"></param>
    public void DateMinimum(DateTime dt)
    {
        rangeUCDate.Enabled = true;
        rangeUCDate.MinimumValue = dt.ToString("MM/dd/yyyy");
        rangeUCDate.MaximumValue = DateTime.Now.AddYears(50).ToString("MM/dd/yyyy");
    }
   
    #endregion

Comments (0)