|
Rank: Newbie Groups: Member
Joined: 10/9/2012 Posts: 2
|
Hi there, I'm trying to set the min and max validdates on a calendar based on the selected item in a dropdownlist. So if a user selects "Normal", only a certain set of dates are valid. if they choose "High" a different set are valid, etc. This is all sitting inside an updatepanel in an asp:Wizard control. Here's the selected aspx:
Code: HTML/ASPX
<asp:DropDownList ID="CRPriority" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SetCalDates">
<asp:ListItem Text="Normal" Value="Normal"></asp:ListItem>
<asp:ListItem Text="High" Value="High"></asp:ListItem>
<asp:ListItem Text="Emergency" Value="Emergency"></asp:ListItem>
<asp:ListItem Text="Retrospective" Value="Retro"></asp:ListItem>
</asp:DropDownList>
<eo:Calendar ID="calSt" runat="server" ControlSkinID="Outlook2003" AllowMultiSelect="false"
FirstDayOfWeek="Monday">
</eo:Calendar>
Here's the code behind:
Code: C#
protected void SetCalDates( object sender, EventArgs e )
{
DropDownList drpPriority = (DropDownList)sender;
EO.Web.Calendar calSt = (EO.Web.Calendar)FindControl( "calSt" );
switch ( drpPriority.SelectedValue )
{
case "Emergency":
calSt.SelectedDate = DateTime.Today;
calSt.MaxValidDate = DateTime.Today.AddDays( 5 );
calSt.MinValidDate = DateTime.Today;
calSt.VisibleDate = DateTime.Today;
break;
case "High":
calSt.SelectedDate = DateTime.Today.AddDays( 6 );
calEn.SelectedDate = DateTime.Today.AddDays( 6 );
calSt.VisibleDate = DateTime.Today.AddDays( 6 );
calSt.MinValidDate = DateTime.Today.AddDays( 6 );
calSt.MaxValidDate = DateTime.Today.AddDays( 10 );
break;
case "Normal":
calSt.SelectedDate = DateTime.Today.AddDays( 11 );
calSt.VisibleDate = DateTime.Today.AddDays( 11 );
calSt.MinValidDate = DateTime.Today.AddDays( 11 );
break;
case "Retro":
calSt.SelectedDate = DateTime.Today.AddDays( -1 );
calSt.VisibleDate = DateTime.Now.AddDays( -1 );
calSt.MaxValidDate = DateTime.Now.AddDays( -1 );
calSt.MinValidDate = new DateTime( 2012, 01, 01 );
break;
default:
break;
}
}
When the page first loads I call the "Normal" selection, which works nicely. However when I change the dropdown selection (from Normal to say High), I get an error stating "bp must be between 2012-10-20 and 9999-12-31". Am I doing something wrong trying to set the calendar this way, or am I doing something in the wrong order? It's puzzling as I'd have thought it'd be quite straightforward! Thanks for your help, it's a great control!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
The code you posted looked quite fine to us. So I would think the problem is somewhere else. As a test, you may want to try to reproduce the problem in a separate blank page, that should usually tell you what's causing it.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 10/9/2012 Posts: 2
|
Hi thanks for getting back so quickly! I tried pulling the specific code out into a new page as suggested, but still had the same issues. However, I decided to add a couple of lines to "reset" the min and max dates before setting them again...
Code: C#
protected void SetCalDates( object sender, EventArgs e )
{
DropDownList drpPriority = (DropDownList)sender;
EO.Web.Calendar calSt = (EO.Web.Calendar)FindControlRecursive( "calSt" );
--> calSt.MinValidDate = new DateTime( 2012, 01, 01 );
--> calSt.MaxValidDate = new DateTime( 9999, 01, 01 );
switch ( drpPriority.SelectedValue )
{
...
So now the code works properly and the dates set fine when the dropdown changes! I'm not sure why doing it this way has caused it to work, but it might help someone in the future... Thanks again for a great control!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi, That's a great discovery and it makes perfect sense. ;) The reason is setting one of the range may not work if it is against the other end of the range. For example, the following code would not work as you expected:
Code: C#
//Set max date to 1/1/2010
calSt.MaxValidDate = new DateTime(2010, 1, 1);
//Set valid range to 1/1/2011 to 1/1/2012
calSt.MinValidDate = new DateTime(2011, 1, 1); // this line will fail
calSt.MaxValidDate = new DateTime(2012, 1, 1);
The second line will fail because the maximum valid date is already set to 1/1/2010, so minimum date can not be higher than that. In order for the new minimum date to take effect, you have to reset the previous maximum date. Hope this makes sense to you. Sorry that we didn't think of this earlier. Thanks!
|
|