locked
TextBox TextMode as date not working as expected RRS feed

  • Question

  • User-909867351 posted

    Hi

    I have one TextBox, TextMode as Date, on my form and I want to set the today date. I write the following code:

    protected void Page_Load(object sender, EventArgs e)
        {
            txtData.Text = DateTime.Today.ToString();
        }

    No luck, nothing happens. But if I don't set the TextMode it works and show the date.

    Any help, please?

    regards

    Thursday, September 20, 2018 6:01 PM

Answers

All replies

  • User2053451246 posted

    Hi

    I have one TextBox, TextMode as Date, on my form and I want to set the today date. I write the following code:

    protected void Page_Load(object sender, EventArgs e)
        {
            txtData.Text = DateTime.Today.ToString();
        }

    No luck, nothing happens. But if I don't set the TextMode it works and show the date.

    Any help, please?

    regards

    Problem explained/solved here:

    https://stackoverflow.com/questions/17226535/unable-to-write-to-asp-net-textbox-control-with-the-html5-date-type

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 20, 2018 6:16 PM
  • User839733648 posted

    Hi mariolopes,

    Because the textbox in .Net with TextMode="date" only supports the YYYY-MM-DD format.

    I suggest that you could modify your code as below.

            protected void Page_Load(object sender, EventArgs e)
            {
                TextBox1.Text = DateTime.Today.ToString("yyyy-MM-dd");
            }

    the result:

    Besides, the TextMode property generally corresponds to the <input type="" /> attribute (excepting multiline which renders a <textarea />).

    ASP.NET 4.x introduced additional values corresponding to new HTML5 input types.

    Internet Explorer 11 does not support most of these new input types, specifically it does not currently support the "date" values.

    FireFox is also not suitable. But Chrome and Microsoft Edge could work well.

    effect on Chrome:

    effect on Microsoft Edge:

    For more details, you could refer to following link down to History to see what is and isn't supported.

    https://www.codeproject.com/Tips/776764/Introducing-Textmode-in-ASP-NET 

    Best Regards,

    Jenifer

    Friday, September 21, 2018 6:05 AM