Textbox TextMode Property Date and DateTimeLocal Using Asp.Net c#

Textbox TextMode Property Date and DateTimeLocal

We need date and datetime use in the Textbox add TextMode =Date or DateTimeLocal in the Textbox property.

                                   DEMO
                                                                                             



HTML CODING

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    <table><tr><td>
        <asp:Label ID="Label1" runat="server" Text="Date"></asp:Label>
        </td><td>
            <asp:TextBox ID="txtDate" runat="server" TextMode="Date"></asp:TextBox>
        </td></tr>
        <tr><td>
            <asp:Label ID="Label2" runat="server" Text="DateTimeLocal"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtDateLocal" runat="server" TextMode="DateTimeLocal"></asp:TextBox>
            </td></tr>
        <tr><td></td><td>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Select" />
            </td></tr>
    </table>
    </div>
    </form>
</body>
</html>


C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Date_DateTime : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime date1, datetime1;

        date1 = Convert.ToDateTime(txtDate.Text);

        datetime1 = Convert.ToDateTime(txtDateLocal.Text);

  Response.Write("<script>alert('" + "Date with Time =" + datetime1.ToString("dd/MM/yyyy hh:mm tt") + "  Date =" + date1.ToString("dd/MM/yyyy") + "')</script>");

    }
}




Add new Webform - add two textbox change property textmode="Date" and "DateTimeLocal"







Add cs file - Textbox selected date convert to DateTime  and get date format 





Textbox Date Validation below like this






Supported Browsers


TextModeNot CompatibleCompatible

DateIE(6,7,8,9,10), FirefoxChrome, Safari, Opera
DateTimeLocalIE(6,7,8,9,10), FirefoxChrome, Safari, Opera



TextMode = "Week" 
<asp:TextBox ID="TextBox1" runat="server" TextMode="Week"></asp:TextBox>


TextModeNot CompatibleCompatible
WeekIE(6,7,8,9,10), FirefoxChrome, Safari, Opera

TextMode = "Color" 

<asp:TextBox ID="TextBox1" runat="server" TextMode="Color"></asp:TextBox>

TextModeNot CompatibleCompatible
ColorIE(6,7,8,9,10), Firefox(Lower Version), SafariChrome, Firefox(Version 29.0.) and Opera

TextMode = "Email" 

<asp:TextBox ID="TextBox1" runat="server" TextMode="Email"></asp:TextBox>



TextModeNot CompatibleCompatible
EmailIE(6,7,8,9), Firefox(Lower Version), SafariIE 10,11,Chrome, Firefox(29), Opera

TextMode = "Month" 

<asp:TextBox ID="TextBox1" runat="server" TextMode="Month"></asp:TextBox>

TextModeNot CompatibleCompatible
MonthIE(6,7,8,9,10), FirefoxChrome, Safari, Opera

TextMode = "Number"
<asp:TextBox ID="TextBox1" runat="server" TextMode="Number"></asp:TextBox>


TextModeNot CompatibleCompatible
NumberIE(6,7,8,9,10), FirefoxChrome, Firefox(29), Safari, Opera

TextMode = "Range" 


<asp:TextBox ID="TextBox1" runat="server" TextMode="Range"></asp:TextBox>


TextModeNot CompatibleCompatible
RangeIE(6,7,8,9), FirefoxIE 10,11, Chrome, Firefox(29), Safari, Opera

TextMode = "Search"

<asp:TextBox ID="TextBox1" runat="server" TextMode="Search"></asp:TextBox>



TextModeNot CompatibleCompatible
SearchIE(6,7,8,9), FirefoxIE 10,11, Chrome, Safari

TextMode = "Time" 

<asp:TextBox ID="TextBox1" runat="server" TextMode="Time"></asp:TextBox>

TextModeNot CompatibleCompatible
TimeIE(6,7,8,9,10), FirefoxChrome, Safari, Opera

 TextMode = "Url" 

<asp:TextBox ID="TextBox1" runat="server" TextMode="Url"></asp:TextBox>


TextModeNot CompatibleCompatible
UrlIE(6,7,8,9), FirefoxIE 10,11, Chrome, Firefox 29, Opera


1 comment:

  1. How validate TextMode=Month ?

    // 2017-05
    var yyyyMM = AddEventMes.Text;
    int? mes = null;
    if (!string.IsNullOrWhiteSpace(yyyyMM))
    {
    var MM = yyyyMM.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
    mes = Utility.TryParseNullable(MM[1].Trim());
    }

    ReplyDelete