本文介绍了如何设置从服务器端code值一个asp.net文本框用的TextMode ="日期和QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一个演示应用程序用于学习用在asp.net文本框控件引入了新的HTML5输入类型(例如─日期,电子邮件等作为的TextMode)的。

I am doing a demo application for learning the use of new HTML5 input types (example- Date, email etc as TextMode) introduced in asp.net textbox control.

在我的示例页面我想用ASP显示服务器端的日期场数据:使用文本框的TextMode =日期

In my sample page I want to display server side date field data using asp:TextBox with TextMode="Date".

在asp.net code云为:

The asp.net code goes as:

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

C#的后端code竟把

The C# backend code goes as

protected void Page_Load(object sender, EventArgs e)
{
    txtExpenseDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
}

不过,虽然在页面加载,日期值不会被显示在文本框中。

But while the page loads, the date value does not get displayed in the textbox.

我是什么做错了吗?

补遗:
刚刚意识到,因为这是HTML5,不得不提的浏览器版本。我对谷歌最新的Chrome版本33.0.1750.117米这将显示字段作为日历挑日期,从而支持的TextMode的HTML5 equivalant =日期属性。

addendum:Just realized that since this is HTML5, I must mention browser version. I am on latest Google Chrome Version 33.0.1750.117 m. This displays the field as a calendar to pick the date, thus supports the HTML5 equivalant of TextMode="Date" attribute .

问候,

萨米特

推荐答案

试试下面的code

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

这篇关于如何设置从服务器端code值一个asp.net文本框用的TextMode =&QUOT;日期和QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:59