I have two calendar controls on a page side-by-side so the users can select a date range (please dont send me any multi-select calendar control options, my users wont like it
). On postback, the most recently clicked calendar will apply its new value, but the other calendar will
reset itself to "DateTime.Today". It does not matter which calendar I select, the opposite one will reset to Today.
For easy navigation on initial page load, I need both calendars to start at todays date (hence DateTime.Today). Some success is gained if I set the default calendar date to
static date in the past (like March 15, 2012), the behavior acts as I want it, BUT The users are stuck at a time in the past when selecting dates on initial page load.
My failed attempts to resolve this have been:
Seperating the C# code so that on init or page_load it sets to Today, THEN, when the control is clicked (event: SelectionChanged) it goes to a new code block that does not contain the DateTime.Today preset. I get the same issue.
Update Panel was added to isolate the changes in the control postback - this renders control useless within the rest of my code AND the same behavior exists.
Just a thought but if the the page_load is setting the values wrap the code in:
if(!this.IsPostback){
//code to set dates
}
this will prevent the dates from being reset when the page posts back to the server. The reason the other control is working is the click event is raised after the Page_Load is fired.
Anthony Terra
Marked as answer by sfink on Apr 11, 2012 12:11 AM
Thanks. I am 1/2 the guru that I think I am, but I have used that one in the past, and KNEW it, just my little brain went blankety blank, sputter, cough......
Thanks for the kick in the head. I should have posted this morning instead of waiting until the end of the day, could have saved myself the brain ache.
Thanks again!
PS: For others that find the answer useful, there is a typo: its "IsPostBack" Capital "B"
sfink
Member
3 Points
9 Posts
Getting Two Calendar Controls to Maintain their ViewState
Apr 10, 2012 10:44 PM|LINK
I have two calendar controls on a page side-by-side so the users can select a date range (please dont send me any multi-select calendar control options, my users wont like it
). On postback, the most recently clicked calendar will apply its new value, but the other calendar will
reset itself to "DateTime.Today". It does not matter which calendar I select, the opposite one will reset to Today.
For easy navigation on initial page load, I need both calendars to start at todays date (hence DateTime.Today). Some success is gained if I set the default calendar date to static date in the past (like March 15, 2012), the behavior acts as I want it, BUT The users are stuck at a time in the past when selecting dates on initial page load.
My failed attempts to resolve this have been:
<asp:Calendar ID="CalFrom" runat="server" BackColor="White" BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="150px" NextPrevFormat="ShortMonth" onselectionchanged="OnDateSelect" Width="250px"> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" /> <DayStyle BackColor="#CCCCCC" /> <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" /> <OtherMonthDayStyle ForeColor="#999999" /> <SelectedDayStyle BackColor="#333399" ForeColor="White" /> <TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True" Font-Size="12pt" ForeColor="White" Height="12pt" /> <TodayDayStyle BackColor="#999999" ForeColor="White" /> </asp:Calendar> </td> <td> <asp:Calendar ID="CalTo" runat="server" BackColor="White" BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="150px" NextPrevFormat="ShortMonth" onselectionchanged="OnDateSelect" style="margin-top: 0px" Width="250px"> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" /> <DayStyle BackColor="#CCCCCC" /> <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" /> <OtherMonthDayStyle ForeColor="#999999" /> <SelectedDayStyle BackColor="#333399" ForeColor="White" /> <TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True" Font-Size="12pt" ForeColor="White" Height="12pt" /> <TodayDayStyle BackColor="#999999" ForeColor="White" /> </asp:Calendar>aterra
Participant
910 Points
162 Posts
Re: Getting Two Calendar Controls to Maintain their ViewState
Apr 10, 2012 11:58 PM|LINK
Just a thought but if the the page_load is setting the values wrap the code in:
if(!this.IsPostback){ //code to set dates }this will prevent the dates from being reset when the page posts back to the server. The reason the other control is working is the click event is raised after the Page_Load is fired.
sfink
Member
3 Points
9 Posts
Re: Getting Two Calendar Controls to Maintain their ViewState
Apr 11, 2012 12:16 AM|LINK
Aterra, YOU are a GAWD!
Thanks. I am 1/2 the guru that I think I am, but I have used that one in the past, and KNEW it, just my little brain went blankety blank, sputter, cough......
Thanks for the kick in the head. I should have posted this morning instead of waiting until the end of the day, could have saved myself the brain ache.
Thanks again!
PS: For others that find the answer useful, there is a typo: its "IsPostBack" Capital "B"
aterra
Participant
910 Points
162 Posts
Re: Getting Two Calendar Controls to Maintain their ViewState
Apr 11, 2012 12:21 AM|LINK
Glad I could help.