Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi how to insert Default date time when i clicked to button and show into textbox?
Posted
Comments
Member 11886593 5-Aug-15 2:25am    
how can i insert my date in any data entry software if the entry is of previous day or weak

Simple

Write this code in the Button Click

C#
textBox1.Text = DateTime.Now.ToString();
 
Share this answer
 
Comments
NandaKumer 28-Jan-12 14:45pm    
good one
 
Share this answer
 
Create your button and your textbox controls:
ASP.NET
<asp:textbox id="TheDateTB" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:button id="TheButton" runat="server" text="Press me" onclick="TheButton_Click" xmlns:asp="#unknown" />

Then on Click event, set the date in the textbox:
C#
protected void TheButton_Click(object sender, EventArgs e)
{
     TheDateTB.Text = DateTime.Now.ToString("MM/dd/yyyy");
}
 
Share this answer
 
Comments
ythisbug 28-Jan-12 8:12am    
wat about time..i need time to display also..any small format for this.
fjdiewornncalwe 28-Jan-12 14:00pm    
.ToString("MM/dd/yyyy hh:mm tt")
daniele.arrighi 28-Jan-12 14:24pm    
or .ToString("MM/dd/yyyy HH:mm:ss") if you want the 24h time format
NandaKumer 28-Jan-12 14:45pm    
good one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900