Microsoft.SharePoint.WebCon ...


RepeatedControls Class (Microsoft.SharePoint.WebControls)

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
<ParseChildrenAttribute(True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
Public Class RepeatedControls
    Inherits Control
    Implements INamingContainer
Visual Basic (Usage)
Dim instance As RepeatedControls
C#
[ParseChildrenAttribute(true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
public class RepeatedControls : Control, INamingContainer
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
    Microsoft.SharePoint.WebControls.RepeatedControls
       Microsoft.SharePoint.WebControls.GenericInformationBar
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Tags :


Community Content

Reza Alirezaei - MVP
Screensot and Source code

For screenshot and source code of the content below , see : http://blogs.devhorizon.com/reza/?p=670



Reza Alirezaei - MVP
RepeatedControls - Part1

Description

The RepeatedControls control inherits System.Web.UI.Control and implement the marker interface INamingContainer. RepeatedControls is a container control which is designed to host other controls known as child controls.Windows SharePoint Services relies on this control to achieve a consistent look and feel to create similar HTML for various toolbars across out of the box Web parts and application pages.

Property AfterControlHTML gets or sets an HTML string to emit after the control itself is rendered whilst property BeforeControlHTML does the same thing, but before the rendition of the control.Property HeaderHtml and FooterHtml expose HTML string containing text to insert to the header/footer of the control. You may choose to use CSS classes to control header/footer appearance; for example, setting HeaderHtml property to the following string would make the toolbar match the styles of an out of the box toolbar. Matching FooterHtml element will have to close the <div> tag which was opened in the header:

HeaderHtml:

"<div class=\"ms-toolbarContainer\" width=\"100%\">"

FooterHtml:

"</div>" 

One of the most powerful properties of this class is called Template_Controls (of type ITemplate) which can be used to define the behavior of the template (child) controls added to this container control. In the CreateChildControl method of RepeatedControls control and only if Template_Controls property is set, a call into InstantiateIn(this) method is made. Once this call is made, it is the templates chance (a separate class file that implements ITemplate) to add its abstract controls into the page’s control tree. The parameter that is parsed in the InstantiateIn method is an instance of RepeatedControls control that acts as the container control.

Usage Scenario

You would typically use the RepeatedControls control to manufacture toolbars that match the styles of the out of the box toolbars. The following examples demonstrate how you can leverage RepeatedControls class to build a Web part with a toolbar and one Refresh button on it.


Thomas Lee
RepeatedControls - Part2

Code Sample in C#

public class WPT : Microsoft.SharePoint.WebPartPages.WebPart {      
protected override void CreateChildControls()
{
TimeToolbar timeToolbar = new TimeToolbar();
timeToolbar.ID = "ToolBar";
this.Controls.Add(timeToolbar);
// Add a refresh button to perform a basic postback to update the current time.
timeToolbar.AddToolbarButton(
"RefreshTime",
"Refresh Time",
this.Page.ClientScript.GetPostBackEventReference(this,String.Empty),
"Refresh the page to reload the current time",
"/_layouts/IMAGES/refresh.gif");
Literal currentTimeToronto = new Literal();
currentTimeToronto.Text = string.Format("<br/>Current Date and Time:</b>{0}<br/>", DateTime.Now.ToString());
this.Controls.Add(currentTimeToronto);
}
}
/// A toolbar class that matches the styles of the out of the box toolbars.
public class TimeToolbar : RepeatedControls
{
public TimeToolbar()
{
this.HeaderHtml =
"<div class=\"ms-toolbarContainer\" width=\"100%\">";
this.FooterHtml = "</div>";
this.SeparatorHtml = "";
}
public void AddToolbarButton(string buttonId,string buttonText,string clientOnClick,string tooltipText,string buttonImageSrc)
{
Literal buttonMarkupLiteral = new Literal();
buttonMarkupLiteral.Text = String.Format(
ButtonImageHtmlFormat,
SPHttpUtility.HtmlEncode(buttonText),
SPHttpUtility.HtmlEncode(clientOnClick),
SPHttpUtility.HtmlEncode(tooltipText),
SPHttpUtility.HtmlUrlAttributeEncode(buttonImageSrc));
buttonMarkupLiteral.ID = buttonId;
this.Controls.Add(buttonMarkupLiteral);
}

// {0} = Button text
// {1} = onclick script
// {2} = Tooltip text
// {3} = Button image markup
private const string ButtonImageHtmlFormat = @"
<DIV class=""ms-toolbarItem ms-selectorlink"">
<A href=""#"" onclick=""{1}"" title=""{2}"">
<IMG alt=""{2}"" src=""{3}"" border=""0"">{0}</A>
</DIV>";
}

Thomas Lee
RepeatedControls - Part3

Code Sample in VB.NET

Public Class WPT
Inherits Microsoft.SharePoint.WebPartPages.WebPart
Protected Overloads Overrides Sub CreateChildControls()
Dim timeToolbar As New TimeToolbar()
timeToolbar.ID = "ToolBar"
Me.Controls.Add(timeToolbar)
' Add a refresh button to perform a basic postback to update the current time.
timeToolbar.AddToolbarButton("RefreshTime", "Refresh Time", Me.Page.ClientScript.GetPostBackEventReference(Me, [String].Empty), "Refresh the page to reload the current time", "/_layouts/IMAGES/refresh.gif")

Dim currentTimeToronto As New Literal()
currentTimeToronto.Text = String.Format("<br/>Current Date and Time:</b>{0}<br/>", DateTime.Now.ToString())
Me.Controls.Add(currentTimeToronto)
End Sub
End Class
''' A toolbar class that matches the styles of the out of the box toolbars.
Public Class TimeToolbar
Inherits RepeatedControls
Public Sub New()
Me.HeaderHtml = "<div class=""ms-toolbarContainer"" width=""100%"">"
Me.FooterHtml = "</div>"
Me.SeparatorHtml = ""
End Sub
Public Sub AddToolbarButton(ByVal buttonId As String, ByVal buttonText As String, ByVal clientOnClick As String, ByVal tooltipText As String, ByVal buttonImageSrc As String)
Dim buttonMarkupLiteral As New Literal()
buttonMarkupLiteral.Text = [String].Format(ButtonImageHtmlFormat, SPHttpUtility.HtmlEncode(buttonText), SPHttpUtility.HtmlEncode(clientOnClick), SPHttpUtility.HtmlEncode(tooltipText), SPHttpUtility.HtmlUrlAttributeEncode(buttonImageSrc))
buttonMarkupLiteral.ID = buttonId
Me.Controls.Add(buttonMarkupLiteral)
End Sub

' {0} = Button text
' {1} = onclick script
' {2} = Tooltip text
' {3} = Button image markup
Private Const ButtonImageHtmlFormat As String = "" & Chr(13) & "" & Chr(10) & " <DIV class=""ms-toolbarItem ms-selectorlink"">" & Chr(13) & "" & Chr(10) & " <A href=""#"" onclick=""{1}"" title=""{2}"">" & Chr(13) & "" & Chr(10) & " <IMG alt=""{2}"" src=""{3}"" border=""0"">{0}</A>" & Chr(13) & "" & Chr(10) & " </DIV>"
End Class
Tags : part3

Page view tracker