How to put today's date as the default value in a texbox as input type date?

3

I have a page to search for a sales report and I use a textbox that generates a input type "date", and every time the page loads the value of the field is "dd / mm / yyyy".

I would like that whenever the page was loaded the field would show the current date without having to open the calendar to choose the date. How can I do this?

    
asked by anonymous 03.09.2015 / 16:23

1 answer

2

As I understand it, you're using a DateTimePicker .

In the Page_Load event, I believe it's just setting the field with the current date.

txtData.Value = DateTime.Today;

EDIT

In the comments, you're getting the following screen as a result:

<input name="calInicio" type="date" id="calInicio" class="form-control" placeholder="DD/MM/AAAA" style="height:32px;width:180px;">

The problem is that <input type="date" ...> must have a date in the format yyyy-mm-dd as initial value (see the part about value ). That is, Page_Load loads its TextBox as follows:

txtInicio.Text = DateTime.Today.ToString("yyyy-MM-dd");
    
03.09.2015 / 16:34