Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the value of a textbox textmode=date ASP.NET C#

Tags:

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.

like image 365
Welington Avatar asked Mar 30 '14 15:03

Welington


People also ask

How to set the value of a TextBox TextMode date ASP net c#?

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.

How to set Date format for TextBox in ASP net?

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.

How to change Date format in TextMode date in ASP net?

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.

How can use date TextBox in asp net?

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.


1 Answers

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.

like image 52
Peter Hahndorf Avatar answered Oct 21 '22 09:10

Peter Hahndorf