Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to show the day name in short form like there MON represent Monday as in asp.net. I want to show the current day on the system of the user like this. I'm using Ajax Control Toolkit to show the calendar while DayNameFoemat is used in the ASP:Calender tag. So I'm unable to do this manually because I want to make it customized way. I also tried to show only date in textbox like this

TextBox1.Text = DateTime.Today.ToString("d");


But it is not giving me the desired output. I want to set the four textboxes for the day,date,month and year and show them separately but I'mm unable to get them in this way. How an I get rid of from this problem? Is it possible or I'm just dreaming?

Is there any way when user select the date from the Ajax calender then all fields changed regarding that.

XML
<ajax:CalendarExtender TargetControlID="TextBox1"
            runat="server" PopupButtonID="image1" TodaysDateFormat="dd"
                PopupPosition="Right">
            </ajax:CalendarExtender>
Posted
Updated 14-Nov-11 21:00pm
v2
Comments
Sergey Alexandrovich Kryukov 15-Nov-11 2:55am    
Not clear what was your idea behind using the format "d"...
--SA

For abreviated day name, try:
C#
TextBox1.Text = DateTime.Today.ToString("ddd");


There is a complete list of the date/time formatting codes here: Formatting a DateTime for display - format string description[^]
 
Share this answer
 
Comments
Ajvirk 15-Nov-11 3:02am    
The first solution working fine for me but I updated my question as what I exactly need to do. if that is possible in the same field or I should have to use a hide panel to show them separate.
Sergey Alexandrovich Kryukov 15-Nov-11 3:03am    
Correct, a 5. Some more detail as well as alternative (DateTimePicker) -- in my solution.
--SA
Custom formatting of System.DateTime is simple. First, you can use different ToSting methods, see http://msdn.microsoft.com/en-us/library/system.datetime.tostring.aspx[^].
Formatting:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

But look for some alternatives. Why do you need all your text boxes at all? Consider using ASP.NET DateTimePicker! See:
http://www.markbeaton.com/SoftwareInfo.aspx?ID=868292da-e93e-4e85-b455-41263ed15cd5[^],
http://weblogs.asp.net/gunnarpeipman/archive/2011/05/15/timepicker-nice-extension-to-jquery-ui-datepicker.aspx[^],
on CodeProject: DateTimePicker Web Control[^].

Enjoy!

—SA
 
Share this answer
 
Comments
Ajvirk 15-Nov-11 3:05am    
Because I'm going to use css with them to dhow them in very custom way so only that way is possible to me to do that. Is there any way to set the TargetControlID of the ajax calender to with other field or not.
C#
TextBox1.Text =DateTime.Now.ToString("ddd MMM dd, yyy"); 
 
Share this answer
 
See this link below, alot of DateTime formats. Knock yourself out!
- http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm[^]

Happy coding,
Morgs
 
Share this answer
 
TextBox1.Text = CalendarExtender1.SelectedDate.ToString("dd"); // Date (13)
TextBox2.Text = CalendarExtender1.SelectedDate.ToString("ddd"); // Day (Sun)
TextBox3.Text = CalendarExtender1.SelectedDate.ToString("MMMM"); // Month (November) & MMM - Short Format ( Jul, Jan)
TextBox4.Text = CalendarExtender1.SelectedDate.ToString("yyyy"); // Year (2011)


You can also use DateTime.ToDay or DateTime.Now instead of "CalendarExtender1.SelectedDate"
 
Share this answer
 
v2

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