2

I use SPCalendarView control as part of my UserControl in WebPart. Does anybody have problem switching between days/weeks in daily/weekly view in SPCalendarView control? There are no problem with switching months (when I'm inheriting System.Web.UI.WebControls.WebParts.WebPart and set EnableV4Rendering to false; when I inherited Microsoft.Sharepoint.WebPartPages.WebPart and set EnableV4Rendering to true I was unable even to switch between months), but when user tries to switch days nothing happens (well, happens post-back and view for same day/week is been loaded). How did you resolve this problem? Sorry for my English.

I found that problem is in JavaScript code which changes selected date: when I'm viewing months it appends ...?CalendarDate= to request string, but when I'm in daily view, it leaves ?CalendarDate= unchanged and appends &date=, which seems to have no influence on displayed content. Any suggestions how to fix this?

0

2 Answers 2

2

OK, I found solution. If you will face the same problem, you could add block such as

if(Page.Request.QueryString["date"] != null)
   _view.SelectedDate = Request.QueryString["date"];

to your Page_Load method. Thread is closed.

2

Although you got the answer, I thought of pasting this reusable code. This method could be used to change the view of SPCalendarView

        private string GetViewType()
    {
        string viewType = string.Empty;
        if (Page.Request.QueryString["CalendarPeriod"] != null)
        {
            switch (Page.Request.QueryString["CalendarPeriod"].ToString().ToLower())
            {
                case "day":
                    viewType = "day";
                    break;
                case "month":
                    viewType = "month";
                    break;
                case "timeline":
                    viewType = "timeline";
                    break;
                default:
                    viewType = "week";
                    break;
            }

        }
        else
        {
         viewType = "week";
        }

        return viewType;
       }

After you have this method in your class, You can just call the above method to switch ViewType of SPCalendarView

            _calendarControl = new SPCalendarView();
        _calendarControl.ViewType = GetViewType();

Hope this helps someone in need.

Thanks, Sudhir Kesharwani

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.