This is a migrated thread and some comments may be shown as answers.

Wrong CSS styles applied after setting value of FocusedDate

4 Answers 111 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Dave Trelfa
Top achievements
Rank 1
Dave Trelfa asked on 26 Nov 2008, 03:51 PM
Hi, I'm having a problem with the calendar control. My implementation calls for me to use my own previous/next month controls rather than the ones built into the navigation bar. I've placed a button on the page, and set a server-side event on it that calls like this:

calendar.FocusedDate = calendar.FocusedDate.AddMonths(1);

This works fine in changing the month, but when the page re-displays, the classes applied to all the day numbers are wrong, the numbers that belong to the previous month are shown in black but the ones for the current month are greyed out. It's as if the CSS is still showing the month I have paged away from as selected. If you hover over the individual day numbers, they reset themselves to the correct style. Any ideas on how to fix this?

Here is the code, I'm using Telerik assembly version 2008.3.1105.20:

testbed.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestBed.aspx.cs" Inherits="Twofour.MediaFreedom.Administration.TestBed" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"
    <title>Test bed</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
     
        <div> 
            <asp:Button ID="btnNext" runat="server" Text="Go To Next Month &gt;&gt;" OnClick="btnNext_Click" /> 
        </div> 
 
        <telerik:RadCalendar ID="calendar" runat="server" /> 
 
    </form> 
</body> 
</html> 

testbed.aspx.cs:

using System; 
using System.Web.UI; 
 
namespace Twofour.MediaFreedom.Administration 
    public partial class TestBed : Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
        } 
 
        protected void btnNext_Click(object sender, EventArgs e) 
        { 
            calendar.FocusedDate = calendar.FocusedDate.AddMonths(1); 
        } 
    } 
 

testbed.aspx.designer.cs:

//------------------------------------------------------------------------------ 
// <auto-generated> 
//     This code was generated by a tool. 
//     Runtime Version:2.0.50727.3053 
// 
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 
 
namespace Twofour.MediaFreedom.Administration { 
     
     
    public partial class TestBed { 
         
        /// <summary> 
        /// form1 control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::System.Web.UI.HtmlControls.HtmlForm form1; 
         
        /// <summary> 
        /// RadScriptManager1 control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::Telerik.Web.UI.RadScriptManager RadScriptManager1; 
         
        /// <summary> 
        /// btnNext control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::System.Web.UI.WebControls.Button btnNext; 
         
        /// <summary> 
        /// calendar control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::Telerik.Web.UI.RadCalendar calendar; 
    } 
 

Thanks,

4 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 01 Dec 2008, 03:03 PM
Hello Dave,

There seems to be an issue with RadCalendar, which occurs when the FocusedDate property is accessed after PostBack.

I suggest that you use the following alternative way to navigate through months:

<div>  
    <asp:Button ID="btnPrev" runat="server" Text="Previous Month" OnClientClick="__doPostBack('RadCalendar1','n:-1');return false;" />  
    <asp:Button ID="btnNext" runat="server" Text="Next Month" OnClientClick="__doPostBack('RadCalendar1','n:1');return false;" />  
</div>  
 
<telerik:RadCalendar ID="RadCalendar1" runat="server" />  
 


Your Telerik points have been updated for bringing the problem to our attention. Thanks.


All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dave Trelfa
Top achievements
Rank 1
answered on 01 Dec 2008, 04:44 PM
This doesn't work if the radcalendar is within a user control. I tried the following but it doesn't appear to work either:

btnPrev.OnClientClick = "__doPostBack('" + RadCalendar1.ClientID + "','n:-1');return false;"

Any ideas?

Also, when the next/previous buttons are clicked, I need to update a Literal to show the current month and year name, this code will not allow me to do that.

0
Accepted
Dimo
Telerik team
answered on 04 Dec 2008, 12:46 PM
Hi Dave,

Here is a sample project, which demonstrates one possible solution to your task.

Greetings,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dave Trelfa
Top achievements
Rank 1
answered on 05 Dec 2008, 03:26 PM
Thanks for the solution, it was actually slightly more complex an example than it needed to be as I had put the next/previous buttons within the usercontrol rather than outside it, so I had not needed to set values between the page and usercontrol. I've taken the essence of your solution though (i.e. using Page_PreRender to set the text), and it works well.

Thanks.
Tags
Calendar
Asked by
Dave Trelfa
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Dave Trelfa
Top achievements
Rank 1
Share this question
or