DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 9 Aug 2007 18:26:44 -0400,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Homer J. Simpson
          2    Homer J. Simpson
          3    Mark Rae [MVP]
                 4    Homer J. Simpson
                        5    Mark Rae [MVP]
                               6    Homer J. Simpson
                                      7    Mark Rae [MVP]
                                      8    Homer J. Simpson
                                      9    Mark Rae [MVP]


Couple of asp:calendar questions...   
I'm porting a classic ASP page with a calendar to ASP.NET.  I appreciate the 
fact that ASP.NET has such a control built-in, but I'm finding it's far less 
flexible than I thought it would have.  I'm sure I must simply have missed a 
few things, so here's a couple of questions:

a) How can I customize the month name?  There's a couple of options, eg, 
month vs month + year, but I'd prefer to have something like "Aug" instead 
of "August"--the amount of space I have horizontally is very limited, and 
"s-e-p-t-e-m-b-e-r" is causing my whole calendar to expand wider than I'd 
like.

b) Similarly, I want to capitalize the month name (eg, "AUG").  I set 
TitleStyle-CssClass to one of my classes, which includes "text-transform: 
capitalize", but it doesn't seem to have any effect on IE6.  Or is that 
supposed to only capitalize the first character?  I could've sworn I've used 
this in the past to capitalize whole strings...

c) Is the VisibleDate property actually ever useful to *retrieve* the 
currently shown month?  The docs claim it can be used both to set and get 
the current month, but so far, everywhere I've tried to use it, it's still 
uninitialized (1/1/0001).

d) I'm trying to replace the Prev/Next month navigation controls with 
images.  Is this not supported?  I've had to revert to setting the 
ShowNextPrevMonth attribute to false and putting my own image buttons on top 
with absolute positioning--yuck.

e) If you're gonna implement your own month navigation buttons and the 
VisibleDate property is always 1/1/0001, how do you intelligently keep track 
of where you are (since apparently the control can't tell you)?  I'm 
currently relying on a session variable in which I store a DateTime.  If the 
variable doesn't yet exist, I set it to DateTime.Now.  Otherwise I adjust 
the month in my button callback (....AddMonths(1) / ...AddMonths(-1)) and 
save the updated value back in the session variable.  Interesting 
side-effect to this approach--if I click the refresh button, the last action 
is repeated, so if I press Next and then hit refresh repeatedly, the month 
moves forward every time.

f) How can I hook up a mouse click event on the title itself (the month)? 
I'd like to use that to return to "today's month" without using additional 
screen real-estate for another button.

g) I don't want the "other month"'s days to show (eg, the first week of 
August shows 29/30/31/1/2/3/4; I'd rather have 
[blank]/[blank]/[blank]1/2/3/4.  Similarly, 6 weeks are always shown--and in 
this particular case, the entire last week is for next month (Sep 2-8).  I 
can understand that having a fixed number of weeks ensures the amount of 
vertical space doesn't change when navigating from month to month, but 
ultimately the developer should be able to decide the sort of behavior he 
wants.  Is this another attribute I've missed?



I could work around a couple of these items by looking at the HTML generated 
and hunting for the tags rendered, but I'd *really* not have to revert to 
these sort of hacks.
Date:Thu, 9 Aug 2007 18:26:44 -0400   Author:  

Re: Couple of asp:calendar questions...   
Nobody, huh?

Ok, I realize I'm an ASP.NET n00b, and a lot of people don't bother with 
entry-level questions.  I'm fine with that; been there, done that, and I'm 
guilty of this myself.

So where (newsgroup, web-based forum, etc) are my type of n00b questions 
welcomed?
Date:Tue, 14 Aug 2007 09:03:24 -0400   Author:  

Re: Couple of asp:calendar questions...   
"Homer J. Simpson"  wrote in message 
news:%23Kn1gRt2HHA.5316@TK2MSFTNGP04.phx.gbl...


> a) How can I customize the month name?  There's a couple of options, eg, 
> month vs month + year, but I'd prefer to have something like "Aug" instead 
> of "August"--the amount of space I have horizontally is very limited, and 
> "s-e-p-t-e-m-b-e-r" is causing my whole calendar to expand wider than I'd 
> like.


MyCalendar.Caption = MyCalendar.VisibleDate.ToString("MMM");


> b) Similarly, I want to capitalize the month name (eg, "AUG").  I set 
> TitleStyle-CssClass to one of my classes, which includes "text-transform: 
> capitalize", but it doesn't seem to have any effect on IE6.  Or is that 
> supposed to only capitalize the first character?  I could've sworn I've 
> used this in the past to capitalize whole strings...


MyCalendar.Caption = MyCalendar.VisibleDate.ToString("MMM").ToUpper();


> c) Is the VisibleDate property actually ever useful to *retrieve* the 
> currently shown month?  The docs claim it can be used both to set and get 
> the current month, but so far, everywhere I've tried to use it, it's still 
> uninitialized (1/1/0001).


How are you setting it?

MyCalendar.VisibleDate = DateTime.Now;


> d) I'm trying to replace the Prev/Next month navigation controls with 
> images.  Is this not supported?


http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.prevmonthtext(vs.80).aspx


> e) If you're gonna implement your own month navigation buttons and the 
> VisibleDate property is always 1/1/0001, how do you intelligently keep 
> track of where you are (since apparently the control can't tell you)?


I'm not sure I understand what you mean... When you click on one of the 
days, the date value is stored in the controls SelectedDate property...


> f) How can I hook up a mouse click event on the title itself (the month)? 
> I'd like to use that to return to "today's month" without using additional 
> screen real-estate for another button.


That's a good one - not sure if there's a property for that...


> g) I don't want the "other month"'s days to show (eg, the first week of 
> August shows 29/30/31/1/2/3/4; I'd rather have 
> [blank]/[blank]/[blank]1/2/3/4.


protected void MyCalendar_DayRender(object source, DayRenderEventArgs e)
{
    if (e.Day.IsOtherMonth)
    {
        e.Cell.Controls.Clear();
        e.Cell.Text = " ";
    }
}


> Similarly, 6 weeks are always shown--and in this particular case, the 
> entire last week is for next month (Sep 2-8).  I can understand that 
> having a fixed number of weeks ensures the amount of vertical space 
> doesn't change when navigating from month to month, but ultimately the 
> developer should be able to decide the sort of behavior he wants.  Is this 
> another attribute I've missed?


Not sure - sorry...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Tue, 14 Aug 2007 14:39:17 +0100   Author:  

Re: Couple of asp:calendar questions...   

>> a) How can I customize the month name?  There's a couple of options, eg, 
>> month vs month + year, but I'd prefer to have something like "Aug" 
>> instead of "August"--the amount of space I have horizontally is very 
>> limited, and "s-e-p-t-e-m-b-e-r" is causing my whole calendar to expand 
>> wider than I'd like.
>
> MyCalendar.Caption = MyCalendar.VisibleDate.ToString("MMM");


Using the caption in place of the month.  Ok, that's an interesting 
approach.

However, the month string that shows up when ShowTitle is set to true is now 
made redundant.  No problem--set it to false, and let Caption take its 
place...only, when ShowTitle is false, the Prev/Next buttons go away (even 
if you force ShowNextPrevMonth to true).  I'd like to keep them.


>> b) Similarly, I want to capitalize the month name (eg, "AUG").  I set 
>> TitleStyle-CssClass to one of my classes, which includes "text-transform: 
>> capitalize", but it doesn't seem to have any effect on IE6.  Or is that 
>> supposed to only capitalize the first character?  I could've sworn I've 
>> used this in the past to capitalize whole strings...
>
> MyCalendar.Caption = MyCalendar.VisibleDate.ToString("MMM").ToUpper();


Same as above.  If I can't use the caption, I still don't have an easy way 
to customize the text.


>> c) Is the VisibleDate property actually ever useful to *retrieve* the 
>> currently shown month?  The docs claim it can be used both to set and get 
>> the current month, but so far, everywhere I've tried to use it, it's 
>> still uninitialized (1/1/0001).
>
> How are you setting it?
>
> MyCalendar.VisibleDate = DateTime.Now;


I'm trying to *retrieve* it, not set it...as in,

DateTime dtCurrentlyShowing = MyCalendar.VisibleDate;  // <-- always 
1/1/0001

Actually, this goes hand-in-hand with your first response.  You suggested:

MyCalendar.Caption = MyCalendar.VisibleDate.ToString("MMM");

....however, the caption shows Jan, not Aug.  Stepping through the code, you 
can see that MyCalendar.VisibleDate is set to 1/1/0001.  Was this off the 
top of your head (I wouldn't blame you), or is it actually working on your 
end??


>> d) I'm trying to replace the Prev/Next month navigation controls with 
>> images.  Is this not supported?
>
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.prevmonthtext(vs.80).aspx


Oh, duh.  :-)  And I see the generated HTML is surrounded by an <a> tag, so 
you don't even have to worry about providing your own onclick event.  Nice.

(As an aside, of course when an image is contained within an archor tag, it 
automatically gets borders, so I had to override that...but that's no 
biggie).


>> e) If you're gonna implement your own month navigation buttons and the 
>> VisibleDate property is always 1/1/0001, how do you intelligently keep 
>> track of where you are (since apparently the control can't tell you)?
>
> I'm not sure I understand what you mean... When you click on one of the 
> days, the date value is stored in the controls SelectedDate property...


That's the thing, I'm not clicking on a day (thus I can't use SelectedDate). 
I'm trying to figure out the current month, so I can use that to calculate 
the previous/next months for my own month navigation buttons.

However this is now a moot point, as I've now replaced the 
Prev/NextMonthText values for my own image tags and don't have to implement 
the actual navigation myself.

OTOH, my question still stands--what if I needed to know the month currently 
shown by the calendar at some other random point in the code--eg, *not* in 
response to a date selection event?  Reading VisibleDate still only shows 
1/1/0001...


>> f) How can I hook up a mouse click event on the title itself (the month)? 
>> I'd like to use that to return to "today's month" without using 
>> additional screen real-estate for another button.
>
> That's a good one - not sure if there's a property for that...


The encapsulating <td> rendered doesn't even have an ID, so I don't know if 
you could get to it other than taking a peek at the calendar's control 
collection and guessing (which would be rather ugly and could easily break).


>> g) I don't want the "other month"'s days to show (eg, the first week of 
>> August shows 29/30/31/1/2/3/4; I'd rather have 
>> [blank]/[blank]/[blank]1/2/3/4.
>
> protected void MyCalendar_DayRender(object source, DayRenderEventArgs e)
> {
>    if (e.Day.IsOtherMonth)
>    {
>        e.Cell.Controls.Clear();
>        e.Cell.Text = " ";
>    }
> }


That looked promising, until I got to the next part (see below)


>> Similarly, 6 weeks are always shown--and in this particular case, the 
>> entire last week is for next month (Sep 2-8).  I can understand that 
>> having a fixed number of weeks ensures the amount of vertical space 
>> doesn't change when navigating from month to month, but ultimately the 
>> developer should be able to decide the sort of behavior he wants.  Is 
>> this another attribute I've missed?
>
> Not sure - sorry...


....the DayRender() override clears the cells, however I've ended up (for 
this particular month) with a completely empty row at the bottom.  It would 
make sense to get rid of that last row entirely...again, hunting for the raw 
tags to manipulate them, instead of using some encapsulating objects, is far 
from ideal...

OTOH, if I leave out e.Cell.Text = " ", the last row doesn't use up any 
space on the screen...even though it still exists as HTML.  Actually, upon 
closer examination, the background color still shows (as a one-pixel row), 
so it would be better to get rid of the last row entirely...

Well, it's still definitely progress.  Thanks for following up.  I thought 
that given the volume in this newsgroup, if I still had no response after 5 
days, my post was going to go unanswered.  I hate to repeat posts in a 
newsgroup.
Date:Tue, 14 Aug 2007 11:15:27 -0400   Author:  

Re: Couple of asp:calendar questions...   
"Homer J. Simpson"  wrote in message 
news:eqCk6Xo3HHA.4400@TK2MSFTNGP06.phx.gbl...


>>> c) Is the VisibleDate property actually ever useful to *retrieve* the 
>>> currently shown month?  The docs claim it can be used both to set and 
>>> get the current month, but so far, everywhere I've tried to use it, it's 
>>> still uninitialized (1/1/0001).
>>
>> How are you setting it?
>>
>> MyCalendar.VisibleDate = DateTime.Now;
>
> I'm trying to *retrieve* it, not set it...as in,
>
> DateTime dtCurrentlyShowing = MyCalendar.VisibleDate;  // <-- always 
> 1/1/0001


Yes, but the VisibleDate property doesn't get set automatically... As it's a 
standard DateTime variable, it will initialise itself to 1/1/0001 until you 
tell it otherwise...

When a Calendar control is first initialised, its TodaysDate property is set 
to the curent date, but not the VisibleDate property...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Tue, 14 Aug 2007 19:41:43 +0100   Author:  

Re: Couple of asp:calendar questions...   

>>> How are you setting it?
>>>
>>> MyCalendar.VisibleDate = DateTime.Now;
>>
>> I'm trying to *retrieve* it, not set it...as in,
>>
>> DateTime dtCurrentlyShowing = MyCalendar.VisibleDate;  // <-- always 
>> 1/1/0001
>
> Yes, but the VisibleDate property doesn't get set automatically... As it's 
> a standard DateTime variable, it will initialise itself to 1/1/0001 until 
> you tell it otherwise...
>
> When a Calendar control is first initialised, its TodaysDate property is 
> set to the curent date, but not the VisibleDate property...


Ok...so the docs are really misleading then.  Here's a quote from my help 
file (from 
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref27/html/P_System_Web_UI_MobileControls_Calendar_VisibleDate.htm)

"Gets or sets a date that specifies the month to display."

My interpretation is that you "should" be able to use it to have the control 
tell you what month is currently being shown.  If that's not the case, then 
I have no idea how you should be able to determine that from any random 
place in your code.
Date:Wed, 15 Aug 2007 11:05:43 -0400   Author:  

Re: Couple of asp:calendar questions...   
"Homer J. Simpson"  wrote in message 
news:uky2R403HHA.2108@TK2MSFTNGP02.phx.gbl...


> Ok...so the docs are really misleading then.  Here's a quote from my help 
> file (from 
> ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref27/html/P_System_Web_UI_MobileControls_Calendar_VisibleDate.htm)
>
> "Gets or sets a date that specifies the month to display."
>
> My interpretation is that you "should" be able to use it to have the 
> control tell you what month is currently being shown.


Yes you can - you just have to initialise it first - loads of properties / 
variables are like that...

DateTime dtmNow;                                // default value i.e. 
1/1/0001
DateTime dtmNow = DateTime.Now;    // current date & time


> If that's not the case, then I have no idea how you should be able to 
> determine that from any random place in your code.


Initialise it when the page loads, then you won't need to worry...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Wed, 15 Aug 2007 16:56:20 +0100   Author:  

Re: Couple of asp:calendar questions...   

> Yes you can - you just have to initialise it first - loads of properties / 
> variables are like that...
>
> DateTime dtmNow;                                // default value i.e. 
> 1/1/0001
> DateTime dtmNow = DateTime.Now;    // current date & time
>
>> If that's not the case, then I have no idea how you should be able to 
>> determine that from any random place in your code.
>
> Initialise it when the page loads, then you won't need to worry...


That's the thing that gets me.  You can put a calendar control on a page and 
it'll automatically show the current month ("current", based on the system 
time).  The user can navigate to other months at will, all without me *ever* 
assigning some initial value--all seemingly to be perfectly valid.  Then if 
I later need to figure out what month is currently shown by the control, I 
have no way of determining that--because I never had to initialize 
VisibleDate to begin with, though it remained fully functional all that 
time.

As far as I'm concerned, it's a quirky design if the control is fully 
functional, but you *still* have to initalize that particular variable 
anyway.  Or the docs should be amended with big bold red letters.  I could 
understand if the control didn't work at all until you initialized it, but 
that's not the case...

Hell of a gotcha if you ask me.  Apparently I'm the only one thinking that. 
:o)
Date:Thu, 16 Aug 2007 18:35:21 -0400   Author:  

Re: Couple of asp:calendar questions...   
"Homer J. Simpson"  wrote in message 
news:Od4cAXF4HHA.484@TK2MSFTNGP06.phx.gbl...


> You can put a calendar control on a page and it'll automatically show the 
> current month ("current", based on the system time).


That's right - the TodaysDate property is initialised to the current date 
time by default...


> The user can navigate to other months at will, all without me *ever* 
> assigning some initial value--all seemingly to be perfectly valid.

Correct.

> Then if  I later need to figure out what month is currently shown by the 
> control, I have no way of determining that--because I never had to 
> initialize VisibleDate to begin with, though it remained fully functional 
> all that time.


That's right - the TodaysDate variable is initialised when the control is 
created, but the VisibleDate isn't...


> Apparently I'm the only one thinking that. > :o)


Apparently so...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Thu, 16 Aug 2007 23:45:05 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us