Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to write to asp.net textbox control with the html5 "date" type

I have an asp.net page with a an html5 TextBox control set as the "date" type. The control on my page looks like this:

<asp:TextBox ID="TextBoxMyDate" runat="server" type="date"/>

It works great in the page and I can click on it and set the date. I can also read the date through TextBoxMyDate.Text. However, I cannot figure out how to programaticaly set the date. I have tried various formats of:

TextBoxMyDate.Text = DateTime.UtcNow.ToString("MM/dd/yyyy") TextBoxMyDate.Text = DateTime.UtcNow.ToString("MM/dd/yyyy")

My guess is that its much more complicated than simply setting the text value but I don't know where to go from here. Any suggestions?

like image 241
Chris Masterton Avatar asked Jun 21 '13 01:06

Chris Masterton


1 Answers

This is actually the correct way to set the date but the format was wrong!

TextBoxMyDate.Text = DateTime.UtcNow.ToString("yyyy-MM-dd");

I was confusing how the browser displays the date and the html5 standards for this control!

like image 50
Chris Masterton Avatar answered Sep 27 '22 22:09

Chris Masterton