KKDev
KKDev

Reputation: 160

Disable previous date and time in text-box mode "date" in ASP.NET

I want to disable previous date and time in textbox (TextMode DateTime)

I#ve tried this in calendar control and that was successful but my requirement is to do it only in textbox.

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e){
    if (e.Day.Date < DateTime.Now.Date){
        e.Day.IsSelectable = false;
        e.Cell.ForeColor = System.Drawing.Color.Gray;
    }
}

Upvotes: 3

Views: 8456

Answers (1)

KKDev
KKDev

Reputation: 160

I have tried many way to resolve this problem but finally i get this solution.

Design

<asp:TextBox ID="txtstartdate" runat="server" TextMode="Date"></asp:TextBox>

Code

txtstartdate.Attributes["min"] = DateTime.Now.ToString("yyyy-MM-dd");

Upvotes: 6

Related Questions