Please help me if you can.
I'm trying to set a textbox textmode=date from a variable.
It's like this:
txtDataDespesa.Text = d.DataDespesa.ToShortDateString();
The problem is, when I go to visualize the page, the value of d.DataDespesa.ToShortDateString()
isn't showing in the txtDataDespesa, instead is the default values dd/mm/yyyy
Thanks in advance.
If you are using textbox with TextMode=”Date”, you need to format the date string before setting value via server side code. Use ToString(“yyyy-MM-dd”) to format the date value before assigning it to the text box. txtEOIStart.
Solution 2 Default format of the DateTime is MM/dd/yyyy. You are providing input in the dd/MM/yyyy. So before converting into the datetime you should convert the user input date time format to the MM/dd/yyyy and then you should typecast.
TextBox with TextMode Date only supports the yyyy-MM-dd format. So you need to set the date format before assigning it to TextBox. You can't change it to dd/MM/yyyy.
The default format of the . NET for displaying the date is MM/dd/yyyy so that the date-picker fails to show the date correctly. To overcome this, we need to add a string type of format in the HTML 5 Date Input Type.
This has nothing to do with asp.net, but Html5. When using type="date"
you should always use the format yyyy-MM-dd
(W3C standard)
The problem is that in browsers that don't support type=date, this will show up as 2014-03-30
, but on browsers that do support it, it is displayed according to the regional settings in the client OS.
So it may be 2014-03-30
, 30.March.2014
or Mar-30-2014
, you have no control over the format, the user has.
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