无法写入asp.net文本框控件与HTML5"日期"类型 [英] Unable to write to asp.net textbox control with the html5 "date" type

查看:213
本文介绍了无法写入asp.net文本框控件与HTML5"日期"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML5的TextBox控件设置为日期类型的asp.net页面。我的页面上的控制是这样的:

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"/>

它在页面的伟大工程,我可以点击它,并设定日期。我还可以阅读TextBoxMyDate.Text的日期。但是,我不知道如何programaticaly设定日期。我已经试过各种格式的:

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)

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?

推荐答案

这其实是正确的方法来设置日期,但格式是错误的!

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

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

我混淆了浏览器如何显示日期和HTML5标准,该控制!

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

这篇关于无法写入asp.net文本框控件与HTML5&QUOT;日期&QUOT;类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆