How to set value from server side code to asp.net text field TextMode = "Date"?

I am making a demo application for exploring the use of the new HTML5 input types (for example, date, email, etc. as TextMode), introduced into the asp.net textbox control.

On my sample page, I want to display the field data on the server side using asp: TextBox with TextMode = "Date".

The asp.net code is as follows:

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

C # backend code looks like

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

But while the page is loading, the date value is not displayed in the text box.

What am I doing wrong?

: , , HTML5, . Google Chrome 33.0.1750.117 . , HTML5 TextMode = "".

,

Sumit

+3
3

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

http://forums.asp.net/t/1856516.aspx?Problem+with+date+textmode+for+textbox+in+vs2012+net+4+5

+5

, .

TextBox Page_Load -

:

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

Your TextMode is set to Date Therefore, you need to convert with the exact date format if you can set textmode as a date. as shown below.

this.txtExpenseDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
this.txtExpenseDate.TextMode=TextBoxMode.Date;
+1
source

All Articles