RadDock for ASP.NET AJAX

RadControls Send comments on this topic.
Adding Content
See Also
Controls > RadDock > RadDock > Adding Content

Glossary Item Box

There are several ways you can set the content inside a RadDock control:

Creating a ContentTemplate at design time

You can add controls to the ContentTemplate property and RadDock will automatically display them runtime.

[ASP.NET] ContentTemplate Copy Code
<telerik:RadDock runat="server" id="RadDock3" Title="ContentTemplate">
 
<ContentTemplate>
   
<div style="margin:10px;">
     
<asp:Label runat="server" id="Label1">You can put text and controls in the ContentTemplate.</asp:Label>
   
</div>
   
<div style="margin:10px;">
     
<asp:Calendar runat="server" id="Calendar1" />
   
</div>
 
</ContentTemplate>
</
telerik:RadDock>

You can access the controls in the ContentTemplate at runtime to get or set their properties:

[C#] Accessing controls in the template Copy Code
protected void Page_Load(object sender, EventArgs e)
{
  
if (!Page.IsPostBack)
  {
     Calendar1.SelectedDate = DateTime.Today;
  }           
}
[VB] Accessing controls in the template Copy Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  If Not Page.IsPostBack Then
    Calendar1.SelectedDate = DateTime.Today
  End If
End Sub

Assigning the ContentTemplate at runtime

You can create a class which implements the ITemplate interface and set its instance to the ContentTemplate property from the code-behind:

[C#] Assigning ContentTemplate at runtime Copy Code
protected void Page_Load(object sender, EventArgs e)
{
 
if (!Page.IsPostBack)
 {
   RadDock1.ContentTemplate =
new CalendarTemplate();
 }
}
class CalendarTemplate : ITemplate
{
 
public void InstantiateIn(Control container)
 {
   Calendar calendar1 =
new Calendar();
   calendar1.ID =
"Calendar1";
   calendar1.SelectedDate = DateTime.Today;
   container.Controls.Add(calendar1);
 }
}
[VB] Assigning ContentTemplate at runtime Copy Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  If Not Page.IsPostBack Then
    RadDock1.ContentTemplate = New CalendarTemplate
  End If
End Sub
Class CalendarTemplate
  Implements ITemplate
  Public Sub InstantiateIn(ByVal container As Control)
    Dim calendar1 As New Calendar()
    calendar1.ID = "Calendar1"
    calendar1.SelectedDate = DateTime.Today
    container.Controls.Add(calendar1)
  End Sub
End Class

Adding controls directly to the content container

Instead of creating a class which implements ITemplate, you can directly add controls to the ContentContainer.Controls collection. This is slightly easier to implement, but you cannot easily reuse the template in other controls.

[C#] Adding controls to ContentContainer Copy Code
protected void Page_Load(object sender, EventArgs e)
{
  Calendar calendar1 =
new Calendar();
  calendar1.ID =
"Calendar1";
  RadDock1.ContentContainer.Controls.Add(calendar1);
}
[VB] Adding controls to ContentContainer Copy Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  Dim calendar1 As New Calendar()
  calendar1.ID = "Calendar1"
  RadDock1.ContentContainer.Controls.Add(calendar1)
End Sub
Note that when using the ContentContainer property, you should always execute the code, even on a postback. This is because controls you add this way are not persisted in the ViewState.

Setting the Text property

If the RadDock control only needs to display plain text, you can use the Text property.

[ASP.NET] Using the Text property Copy Code
<telerik:RadDock
 
ID="RadDock1"
 
runat="server"
 
Text="This text appears in the content area of the RadDock control when there is no template." >
</
telerik:RadDock>

See Also