Search code examples
vb.netdatetextbox

Display date in TextBox with type="date"


I want to display stored date on database on TextBox type="date"

 <asp:TextBox ID="DateStatus"  runat="server" Type="date" CssClass="form-control"></asp:TextBox> 

but nothing is displayed in the textbox i used. I tried this

Dim getdate As Date = DetailTable.Rows(0)(3)
DateStatus.Text= getDate

Also this which i found here

 Dim getdate As Date = DetailTable.Rows(0)(3)
 DateStatus.Text = DateTime.UtcNow.ToString(getdate)

When i debugged the code, the date passed correctly.

When i remove type="date" the requested date is displayed just fine

Is it not Possible to do this?

on SideNote when i generate my table using <Asp:detailsview> the date is generated with time 12:00:00 despite the field declared only as Datein the schema, but i don't think it's relevant to my current issue since every thing looked fine during debugging

And Originally i store the date as Text (@date, DateStatus.Text)


Solution

  • This is HTML 5 stuff. If you have a real date from your database, I simulated like this

    <asp:TextBox ID="txt1" runat="server" TextMode="date" />
    
            Dim d As New Date(1922, 12, 25)
            txt1.Text = d.ToString("yyyy-MM-dd")
            'displays 12/25/1922
    

    HTML 5 expects a string in the format yyyy-MM-dd and a supporting browser will display depending on Culture setting.