Last post Sep 27, 2013 02:27 AM by keshavkumar.pune
Sep 25, 2013 12:51 AM|tomwill|LINK
I changed my textbox mode to date and now the current date doesn't display on the textbox why is that here is the code?
<asp:TextBox ID="date" runat="server" Height="22px" ReadOnly="True"
style="text-align: center" Width="155px" AutoPostBack="True"
date.Text = DateTime.Now.ToString("dd/MM/yyyy");
Sep 25, 2013 01:01 AM|mdsajidfaizan|LINK
There is no date attribute for the textbox mode, only password, multiple and single is there. So you cannot use the Date directly here. You just remove the textmode the code will work. If you want to do the same use
Sep 25, 2013 01:07 AM|tomwill|LINK
yeh i know it works if i put the textmode to singleline but the problem is when i want insert this date into my database i can't because the column name currentDate is set to date
Sep 25, 2013 01:08 AM|oned_gk|LINK
Sep 26, 2013 10:05 AM|BillJordan34|LINK
Delete out your TextMode="Date" so it is a normal textbox. Then on your insert command to your database, set your currentDate column to use the value of the text box.
currentDate = Convert.ToDateTime(date.Text)
string command = "Insert Into table_name (currentDate) Values (" + Convert.ToDateTime(date.Text) + ")";
If this helps you, please mark this post as answered.
Sep 27, 2013 02:27 AM|keshavkumar.pune|LINK
TextMode="Date" is introduced in asp.net 4.5 only to keep the asp.net in sync with HTML5 to allow entering date only in textbox.
If you want to save the text of Textbox as a date,then you will have to explicitly typecast text of textbox to date(as told by
BillJordan34) as the Text property of textbox always returns string.