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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MuthuMari MPosted Apr 9, 2012, 2:54 AM
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"
selvi subramanianPosted Apr 10, 2012, 7:46 AM
SenthilkumarPosted Apr 9, 2012, 8:32 AM
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