How to get the time in a textbox from pageload
how to get the time in a textbox from pageload in asp.net
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
MuthuMari MRank #5,738 · 288 reputationPosted Apr 8, 2012, 10:54 PM EDT
If you retrive the data from the data base, you have to use data reader, after reading the data you have assign that value in to the textbox.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
TextBox3.Text = DateTime.Now.ToShortDateString();
}
}
thanks.
If this post is useful then mark it as "Accepted Answer"
SenthilkumarRank #387 · 6.5K reputationPosted Apr 9, 2012, 4:32 AM EDT
If you want to load the Date and time into text box then
protected void page_load(object sender, Eventargs e)
{
if(!page.IsPostBack)
{
txtDate.Text = DateTime.Now.ToString(); //It shows the date and time in standard format.
}
}
You can customize the date and time using the format specifier.
txtDate.Text = String.Format("d",DateTime.Now.ToString());
like that you can use any format in the below table.
<%= String.Format("{specifier}", DateTime.Now) %>
You can refer the following url as well:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
selvi subramanianRank #2,007 · 723 reputationPosted Apr 10, 2012, 3:46 AM EDT