This post is going to be a summary of some of some the SharePoint controls I regularly use in my solutions. Cool thing about re-using the controls that are already out there is, that saves time in re-inventing the wheel and you don’t have to worry about keeping the look&feel consistent ;)
First, check out the following blog posts for more information on re-using the out-of-the-box controls of SharePoint
Now some controls are already covered by the links that are stated above, so this is really just a quick summary on the things I like to use most ;)
I’ve given each control a table, in the first row there is a screenshot (if applicable) how to control looks like when it’s rendered by SharePoint,
in the second row there is the declarative way of using the control,
in the third row there is (also, if applicable) some codebehind logic on how to use the control and it’s value.
WebApplicationSelector
 |
<SharePoint:WebApplicationSelector ID="webApplicationSelector" runat="server" />
|
protected WebApplicationSelector webApplicationSelector;
..
SPWebApplication webApplication = webApplicationSelector.CurrentItem;
|
SiteAdministrationSelector
 |
<SharePoint:SiteAdministrationSelector runat=server ID="siteadminselector" />
|
protected SiteAdministrationSelector siteAdministrationSelector;
..
SPSiteAdministration siteAdmin = siteAdministrationSelector.CurrentItem;
|
SchedulePicker , for more info on this one and when & why you should use this please read “Using the SchedulePicker” ;)
 |
<%@ Register TagPrefix="wssuc" TagName="SchedulePicker" src="~/_controltemplates/SchedulePicker.ascx" %>
<wssuc:SchedulePicker id="schedulePicker"Hourly="True" Weekly="True" Monthly="True" Enabled="True" EnableStateView="True" runat="server"/>
|
protected SchedulePicker schedulePicker;
..
//Getting a schedule from the picker
SPSchedule schedule = schedulePicker.Schedule;
//Setting the schedule of the picker
schedulePicker.ScheduleString = schedule.ToString();
|
SPDatePickerControl
|
<script type="text/javascript"
src="/_layouts/datepicker.js"></script>
<SharePoint:SPDatePickerControl id="datePickerControl"
runat="server"/>
|
ButtonSection
 |
<%@ Register TagPrefix="wssuc" TagName="ButtonSection"
src="~/_controltemplates/ButtonSection.ascx" %>
<wssuc:ButtonSection runat="server">
<Template_Buttons>
<asp:Button runat="server" class="ms-ButtonHeightWidth"
OnClick="OnClickOK" Text="<%$Resources:wss,multipages_okbutton_text%>"
id="btnOk" accesskey="<%$Resources:wss,okbutton_accesskey%>"/>
</Template_Buttons>
</wssuc:ButtonSection>
|
When making use of the LayoutsPageBase in your codebehind, you can define the URL of the Cancel button by using this snippet:
public override string PageToRedirectOnCancel
{
get
{
//return base.PageToRedirectOnCancel;
return "/_layouts/settings.aspx";
}
}
|
InputFormSection & InputFormControl
 |
<%@ Register TagPrefix="wssuc"
TagName="InputFormSection"
src="~/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc"
TagName="InputFormControl"
src="~/_controltemplates/InputFormControl.ascx" %>
<wssuc:InputFormSection Title="InputFormSection"
Description="InputFormSection Description" runat="server">
<template_inputformcontrols>
<wssuc:InputFormControl runat="server" LabelText="InputFormControl Text">
<Template_Control>
<%--Put a control here--%>
</Template_Control>
</wssuc:InputFormControl>
</template_inputformcontrols>
</wssuc:InputFormSection>
|
InputFormTextBox, notice there are two InputFormTextBoxes shown here. One with the RichTexT property set to true and the other set to false. So with a simple property change you can get the nicely and shiny FullHTML textbox.
 |
<SharePoint:InputFormTextBox ID="ApproveMailSubject" RichText="false" runat="server" Width="100%"/>
<SharePoint:InputFormTextBox ID="ApproveMailContent" RichText="true"
RichTextMode="FullHtml"
runat="server"
TextMode="MultiLine"
Rows="20"/>
|
InputFormRequiredFieldValidator
 |
<wssawc:InputFormTextBox ID="uxFirstName" RichText="false"
TextMode="Singleline" runat="server" Width="100%"/>
<wssawc:InputFormRequiredFieldValidator ID="uxFirstNameValidator"
ControlToValidate="uxFirstName" Text="Error" runat="server"
ErrorMessage ="First name is required"
EnableClientScript="true" Display="Dynamic">
</wssawc:InputFormRequiredFieldValidator>
|
InputFormRangeValidator
|
<wssawc:InputFormRangeValidator
ID="inputFormRangeVal"
Type="Integer" MinimumValue="1" MaximumValue="30"
ControlToValidate="uxNumberOfDays"
ErrorMessage="Value must between 1 and 30"
Runat="server" />
|
ToolBar & ToolBarButton
 |
<%@ Register TagPrefix="wssuc" TagName="ToolBar"
src="~/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton"
src="~/_controltemplates/ToolBarButton.ascx" %>
<wssuc:ToolBar id="Toolbar" runat="server">
<template_buttons>
<wssuc:ToolBarButton runat="server"
id="ViewSites"
Text="View Sites"
ToolTip=""
OnClick="ViewSites_Link"
ImageUrl="/_layouts/images/newitem.gif"
Padding="2px"
AccessKey="V" />
</template_buttons>
<template_rightbuttons>
<SharePoint:WebApplicationSelector id="Selector" runat="server"/>
</template_rightbuttons>
</wssuc:ToolBar>
|
To use the ToolBar in your WebPart you can load the UserControls and reference them using this:
protected ToolBarButton ToolBarButton;
protected ToolBar ToolBar;
..
//Adding a ToolBarButton
ToolBarButton =
(ToolBarButton)Page.LoadControl("/_controltemplates/ToolBarButton.ascx");
ToolBarButton.Click += new EventHandler(ToolBarButton_Click);
ToolBarButton.Text = "Complete selected tasks";
ToolBarButton.ImageUrl = "/_layouts/images/CheckNames.gif";
//Adding the ToolBar
ToolBar =
(ToolBar)Page.LoadControl("/_controltemplates/ToolBar.ascx");
ToolBar.Buttons.Controls.Add(ToolBarButton);
this.Controls.Add(ToolBar);
|