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.
In my sample page I want to display server side date field data using asp:TextBox with TextMode="Date".
The asp.net code goes as:
<asp:TextBox ID="txtExpenseDate" TextMode="Date" runat="server"></asp:TextBox>
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.
What am I doing wrong?
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 .
Regards,
Sumit
Try the below code
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
But while the page loads, the date value does not get displayed in the textbox.
You need to set the value for the TextBox
control in Page_Load
event of the Webpage
Try This:
protected void Page_Load(object sender, EventArgs e)
{
txtExpenseDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
}
Your TextMode set as Date So you need to convert at exact as date format optionally you can set textmode as date. like below.
this.txtExpenseDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
this.txtExpenseDate.TextMode=TextBoxMode.Date;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With