Referencing the template in the designer view
To reference the template in the designer view, perform the following:
-
Reference the embedded template by pasting the following code into DatePickerDesignerView.cs:
protected override string LayoutTemplateName
{
get
{
return "DatePicker.Designer.Views.DatePickerDesignerView.ascx";
}
}
-
Provide reference to the RadDatePicker controls that define the minimum and maximum dates by pasting the following code:
public virtual RadDatePicker MinimumPicker
{
get
{
return this.Container.GetControl<RadDatePicker>("minimumDate", true);
}
}
public virtual RadDatePicker MaximumPicker
{
get
{
return this.Container.GetControl<RadDatePicker>("maximumDate", true);
}
}
-
Override the InitializeControls method and leave its body empty:
protected override void InitializeControls(GenericContainer container)
{
}
-
Provide a property for the HTML tag for the control by pasting this code:
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Div;
}
}
-
Save the file.
To specify a default template for the control, you must override the LayoutTemplateName property in the DatePickerDesignerView class. It must return a string that is a reference to the embedded resource that represents your template.
The template that you defined in Creating the template of the designer view, uses two RadDatePicker controls for setting the minimum and maximum dates. You must create instances of the controls to access the selected values. To reference the controls from theDatePickerDesignerView.ascx you must call GetControl and returning the controls’ values.
NOTE: When using templates make sure you address the controls after they have been initialized. The moment, where the template is initialized and ready to use, is the InitializeControls method. In it and after its execution, you can safely call your controls. You can call theEnsureChildControls() method before every reference to a template control.
Next, you must implement the features of the designer view. For more information, see Implementing the features of the designer view.