Last post Feb 28, 2007 03:08 PM by Cissi
Oct 05, 2006 11:00 PM|barryman9000|LINK
I am migrating from VB to C#, and would like one of my textboxes to be populated with today's date. In VB, I would use:
tbDate.Text = Date.Today()
And it works great. How can I do this with C#? Or is there an easier way I can add the date directly to the Textbox control?
Oct 05, 2006 11:37 PM|Connect|LINK
Oct 05, 2006 11:49 PM|Haissam|LINK
You can use this method DateTime.Now() which will return the current date and time on this computer
tbDate.Text = DateTime.Now();
Oct 05, 2006 11:50 PM|ItayZ|LINK
this.tbDate.Text = DateTime.Today.ToString("dd/MM/yyyy");
or any other acceptable date format
Oct 05, 2006 11:50 PM|lbue|LINK
Oct 05, 2006 11:51 PM|barryman9000|LINK
Yeah, I've been messing around with that all day, but nothing seems to work. Any help?
tbDate.Text = DateTime.Now.ToShortDateString();
tbDate.Text = DateTime.Now.ToString();
tbDate.Text = DateTime.Now.Date.ToString();
tbDate.Text = DateTime.Today.ToString();
Oct 06, 2006 12:01 AM|barryman9000|LINK
I must be taking crazy pills... not one of these suggestions has worked.
I'm trying to have today's date show up in a textbox when the page loads. Using VB, the code is just:
Protected Sub Page_Load(ByVal sender
ByVal e As System.EventArgs)
But for some reason, I can't get the date (10/5/06) to show up with the page in C#. All I see is an empty textbox, no errors.
Oct 06, 2006 12:02 AM|Connect|LINK
Oct 06, 2006 12:20 AM|barryman9000|LINK
Although every other VB.NET page I have has AutoEventWireup set to "False," I changed it to "true" for this C# page, and now it works. Is that just something different with C# code and ASP.NET?
In any case, it's working now.
Thanks for all your help, I appreciate it!
Oct 06, 2006 12:29 AM|Connect|LINK
Oct 06, 2006 12:36 AM|barryman9000|LINK
Feb 28, 2007 03:08 PM|Cissi|LINK
I tried your example, and it helped me a lot!