Son of SmartPart Quickstart
This article will show you how you can create your first .NET 2.0 user control and show it in a SharePoint site. First you need to deploy the Son of SmartPart to your SharePoint server of course. Check the Installation Guide which you can find in the zip file that can be downloaded from www.smartpart.info, or watch this installation screencast. When this is done, open up your brand new Visual Studio 2005 and create a new ASP.NET Website. In the Website menu choose “Add new item”, and add a new Web User Control to the project, named DemoControl.asxc.
Now let’s implement the desired functionality! Drag-and-drop a Calendar control from your toolbox on the newly created Web User Control. You can do this both in design and source view, but in the source view you immediately see the result. You can use the SmartTag to Auto Format the control, I’ve selected the professional look of course. :-)
It’s time to write some code so switch to code view, and in the Page_Load event write following code:
public partial class DemoControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Calendar1.Width = new Unit("100%");
Calendar1.SelectionMode = CalendarSelectionMode.None;
Calendar1.TodaysDate = DateTime.Now;
}
}
Optionally you can test your user control by putting it on your default.aspx page for example. But lets immediately fast forward to the deployment of your work to SharePoint. Open the folder in which your web site is located (typically \My Documents\Visual Studio 2005\WebSites\NameOfSite) and copy DemoControl.ascx and DemoControl.ascx.cs to the \UserControls folder of your SharePoint site (check the installation guide if you don’t know what I’m talking about). Next you can open the SharePoint site where you’d like to add the user control as a web part. On the top right of the page, click “Modify Shared Page”, “Add Web Parts”, “Browse” and drag-and-drop an instance of the SonOfSmartPart UC web part to your page.
Click the “Open the tool pane” link on the SmartPart and select the “usercontrols_democontrol_ascx” from the top drop down. Additionally you can also choose a title for your web part. When you’re done click the OK button at the bottom of the page. Now you’re ASP.NET 2.0 UserControl is displayed in a SharePoint site!