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

Custom Control ITemplate Property Error

5 Answers 129 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 09 Feb 2009, 10:10 PM
I have created a custom control which includes a RadScheduler as one of its child controls. I exposed the AdvancedEditTemplate and AdvancedInsertTemplate properties of the RadScheduler in my custom control as shown in the example below.

Imports Telerik.Web.UI 
 
Public NotInheritable Class CustomScheduler 
  Inherits CompositeControl 
 
  Private WithEvents mScheduler As RadScheduler 
 
  <TemplateContainer(GetType(BTAppointmentScheduler)), _ 
    PersistenceMode(PersistenceMode.InnerProperty)> _ 
  Public Property AppointmentFormTemplate() As ITemplate 
    Get 
      EnsureChildControls() 
      Return mScheduler.AdvancedEditTemplate 
    End Get 
    Set(ByVal value As ITemplate) 
      EnsureChildControls() 
      mScheduler.AdvancedEditTemplate = value 
      mScheduler.AdvancedInsertTemplate = value 
    End Set 
  End Property 
 
  Protected Overrides Sub CreateChildControls() 
    Controls.Clear() 
    mScheduler = New RadScheduler() 
    Controls.Add(mScheduler) 
  End Sub 
 
  Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) 
    mScheduler.RenderControl(writer) 
  End Sub 
End Class 

Then I setup my aspx page similiar to the example below.

<my:CustomScheduler ID="CustomScheduler1" runat="server"
  <AppointmentFormTemplate> 
    <asp:TextBox ID="SubjectTextBox" runat="server" Rows="5" Columns="20" Text='<%# Bind("Subject") %>' Width="95%" TextMode="MultiLine"></asp:TextBox> 
    ... 
  </AppointmentFormTemplate> 
</my:CustomScheduler> 

Whenever, I try to create an appointment I get the following exception:

Unable to cast object of type 'System.Web.UI.CompiledTemplateBuilder' to type 'System.Web.UI.IBindableTemplate'.
atTelerik.Web.UI.RadScheduler.CreateFormContainer()
atTelerik.Web.UI.RadScheduler.CreateChildControls(BooleanbindFromDataSource)
atTelerik.Web.UI.RadScheduler.CreateChildControls()
atSystem.Web.UI.Control.EnsureChildControls()
atSystem.Web.UI.Control.PreRenderRecursiveInternal()
atSystem.Web.UI.Control.PreRenderRecursiveInternal()
atSystem.Web.UI.Control.PreRenderRecursiveInternal()
atSystem.Web.UI.Control.PreRenderRecursiveInternal()
atSystem.Web.UI.Control.PreRenderRecursiveInternal()
atSystem.Web.UI.Control.PreRenderRecursiveInternal()
atSystem.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)


What am I doing wrong?

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 Feb 2009, 06:03 PM
Hi Eric,

Please try applyting this attribute:

<TemplateContainer(GetType(BTAppointmentScheduler), BindingDirection.TwoWay)>
Best wishes,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Eric
Top achievements
Rank 1
answered on 10 Feb 2009, 06:22 PM
That seems to have resolved the cast exception in RadScheduler.CreateFormContainer(). I am now getting the following cast exception during databinding.

Unable to cast object of type 'Telerik.Web.UI.SchedulerFormContainer' to type 'MyProject.CustomScheduler'.
at ASP.default_aspx.__DataBinding__control7(Object sender, EventArgs e) in C:\projects\MyProject\Default.aspx:line 36
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.CompositeControl.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at Telerik.Web.UI.RadScheduler.CreateChildControls(Boolean bindFromDataSource)
at Telerik.Web.UI.RadScheduler.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
0
Eric
Top achievements
Rank 1
answered on 10 Feb 2009, 09:04 PM
I must have made a build error. It is working correctly now. Thanks.
0
Eric
Top achievements
Rank 1
answered on 11 Feb 2009, 09:55 PM
It was not a build issue that caused the cast exception during databinding. I had temporarily removed the binding expression. When I added it back in the exception returned.
0
Eric
Top achievements
Rank 1
answered on 13 Feb 2009, 03:31 AM
I was able to resolve the cast exception on data binding by changing the TemplateContainerAttribute as follows:

<TemplateContainer(GetType(SchedulerFormContainer), BindingDirection.TwoWay)>
Tags
Scheduler
Asked by
Eric
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Eric
Top achievements
Rank 1
Share this question
or