9

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?

0

2 Answers 2

13

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!

Sign up to request clarification or add additional context in comments.

Comments

-1

Yes, it is quite possible. Here is an example of a date selection filter with ajaxcontrotoolkit and the textbox field.

Overview:calendar ajaxControlToolkit Overview

Tutorial:Tutorial ajaxControlTollkit Date textbox

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
</asp:ToolkitScriptManager>  

<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>  

<asp:CalendarExtender   
    ID="CalendarExtender1"   
    TargetControlID="txtStartDate"   
    runat="server" /> 

1 Comment

OP was asking how to resolve issues with using <textbox textmode="date">, not other ways to implement a datepicker.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.