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

iCalendar export and LoadTemplate

6 Answers 72 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Thomas Weilgaard Yde
Top achievements
Rank 2
Thomas Weilgaard Yde asked on 18 Jan 2011, 10:40 AM
Hi Telerik, 
I have a problem with the RadScheduler and exporting the appointment when loading templates. I took a look at your solution at http://demos.telerik.com/aspnet-ajax/scheduler/examples/export/defaultcs.aspx and found that when i use dynamic loaded templates it doesn't work correct with my OnAppointmentCommand event method:

I have this in my aspx page:
protected void Page_PreRender(object o, EventArgs e)
{
        switch (radScheduler.SelectedView)
        {
case SchedulerViewType.DayView:
                {
radScheduler.AppointmentTemplate = LoadTemplate("Controls/DayViewTemplate.ascx");
break;
}
}
}

Default.aspx: 
function Export(sender, event) {
        alert(sender.name);
            $find("<%=RadAjaxManager1.ClientID %>").__doPostBack(sender.name,"");
        }

My template is simple at the moment and looks like this (for testing): 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DayViewTemplate.ascx.cs" Inherits="Modules_Scheduler_Controls_DayViewTemplate" %>
<asp:Button ID="lbExport" runat="server" CommandName="Export" Text="iCalendar" OnClientClick="Export(this,event); return false;"></asp:Button>

When I use alert(sender.name) from the javascript I get this "ctl00$Content2$radScheduler$ctl97$ctl01$lbExport" and it throws a postback that just doesnt reach the OnAppointmentCommand

However if I take what is in my template and use it directly on the aspx page like:
<Telerik:RadScheduler ....>
<AppointmentTemplate>
<asp:Button ID="lbExport" runat="server" CommandName="Export" Text="iCalendar" OnClientClick="Export(this,event); return false;"></asp:Button>
</AppointmentTemplate>
</Telerik:RadScheduler>

It throws the correct postback with the command and reaches my Event method. And I get my export file for iCalendar.

So my problem is the above doesn't work when I dynamic load templates for the RadScheduler. So I was wondering if I'm doing something wrong? 
Any tips or help would be much appreciated.

Best regards
Thomas


6 Answers, 1 is accepted

Sort by
0
Thomas Weilgaard Yde
Top achievements
Rank 2
answered on 19 Jan 2011, 08:06 AM
Anyone? :)
Any tips would be welcome!
0
Thomas Weilgaard Yde
Top achievements
Rank 2
answered on 21 Jan 2011, 09:46 AM
Could use some input... thanks! :)
0
Veronica
Telerik team
answered on 21 Jan 2011, 01:24 PM
Hi Thomas Weilgaard Yde,

You need to subscribe to the OnAppointmentCreated event instead of Page_PreRender and use the following code:

protected void RadScheduler1_OnAppointmentCreated(object sender, AppointmentCreatedEventArgs e)
        {
            switch (RadScheduler1.SelectedView)
            {
                case SchedulerViewType.DayView:
                    {
                        ITemplate template = LoadTemplate("DayViewTemplate.ascx");
                        template.InstantiateIn(e.Container);
                        break;
                    }
            }     
        }

As the template is already instantiated by the time that the AppointmentCreating event is raised you should instantiate it explicitly.

All the best,
Veronica Milcheva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Thomas Weilgaard Yde
Top achievements
Rank 2
answered on 24 Jan 2011, 10:00 AM
Hi Veronica, 
(sorry for the format, something weird happened when i used the code format, I can't remove the bottom scroll bar) 

I tried your way but it seems as it adds my appointment after rendering its own template, so I'm running with both the default template and the dynamic template. 

void radScheduler_AppointmentCreated(object sender, Telerik.Web.UI.AppointmentCreatedEventArgs e)
    {
        ITemplate template = null;
  
        switch (RadScheduler_SelectedViewType)
        {
            case SchedulerViewType.DayView:
                {
                    template = LoadTemplate("Controls/DayViewTemplate.ascx");
                    break;
                }
            case SchedulerViewType.WeekView:
                {
                    template = LoadTemplate("Controls/DayViewTemplate.ascx");
                    break;
                }
            case SchedulerViewType.MonthView:
                {
                    template = LoadTemplate("Controls/MonthViewTemplate.ascx");
                    break;
                }
            case SchedulerViewType.MultiDayView:
                break;
            case SchedulerViewType.TimelineView:
                {
                    template = LoadTemplate("Controls/MonthViewTemplate.ascx");
                    break;
                }
            default:
                break;
        }
  
        if (!Object.Equals(template, null))
        {
             template.InstantiateIn(e.Container);
        }
}

appointments shows like this:
|---------------------|
|default template     |
|---------------------|
| my template         |
|---------------------|

I get the template loaded, but still the same result as before, it fires the postback but not catching it correctly. 
protected void radScheduler_AppointmentCommand(object sender, AppointmentCommandEventArgs e)
   {
       switch (e.CommandName)
       {
           case "Export":
               {
                   WriteCalendar(RadScheduler.ExportToICalendar(e.Container.Appointment, radScheduler.TimeZoneOffset));
                   break;
               }
          default:
               break;
       }
   }



0
Thomas Weilgaard Yde
Top achievements
Rank 2
answered on 24 Jan 2011, 10:56 AM
Hi Veronica, 

I made a sample to show you my problem.
Hope you can see what I'm trying to do. 

My Website Project (download file) 

Best regards
 - Thomas
0
Veronica
Telerik team
answered on 27 Jan 2011, 02:17 PM
Hi Thomas Weilgaard Yde,

I've updated your project so now both buttons work OK. Please take a look at the code and let me know if you have some questions.

P.S: Note that I've changed the way RadScheduler is bound (in my case to XMLProvider) because I don't have your database.

Greetings,
Veronica Milcheva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Scheduler
Asked by
Thomas Weilgaard Yde
Top achievements
Rank 2
Answers by
Thomas Weilgaard Yde
Top achievements
Rank 2
Veronica
Telerik team
Share this question
or