ASP.NET Portal Starter Kit Documentation
 

Creating Custom Portal Modules
A portal module combines some code and UI to present specific functionality to the user (for example, a threaded discussion) or render data, graphics and text, (for example, a "sales by region" report). In addition, a portal module needs to know how to interact with the Portal Framework to participate in the rendering, editing, caching and roles-based security services it provides.

Portal modules are implemented as standard ASP.NET User Controls. The logic required to enable the user control to work inside the Portal Framework is encapsulated in a special base class: ASPNetPortal.PortalModuleControl. To create a custom portal module, simply make a User Control that inherits from the ASPNetPortal.PortalModuleControl class.

Hello World

For example, here's a simple "Hello World" portal module (HelloWorld.ascx).
 
    <%@ Control Inherits="ASPNET.StarterKit.Portal.PortalModuleControl" %>

    Hello World!
                
  Using CSS Styles in Portal Modules

The Portal Framework includes a stylesheet called Portal.css that is applied to all tabs in the portal. You can use the styles defined in Portal.css to make the appearance of your custom module consistent with the built-in modules. The most commonly used style is "Normal", which is applied to most text rendered by modules. Here we've updated HelloWorld.ascx to use a style.
 
    <%@ Control Inherits="ASPNET.StarterKit.Portal.PortalModuleControl" %>

    <span class="Normal">Hello World!</span>
                
  Adding a Title to Your Module

When the portal administrator adds an instance of a module to the portal, she can give it a descriptive title. If you want your module to display it's title like the standard portal modules, add the DesktopModuleTitle user control to your module. The DesktopModuleTitle user control knows how to get the module's title from the Portal Framework, and render it consistently with the rest of the portal.

 
    <%@ Control Inherits="ASPNET.StarterKit.Portal.PortalModuleControl" %>
    <%@ Register TagPrefix="Portal" TagName="Title" Src="~/DesktopModuleTitle.ascx" %>

    <portal:title runat="server" />
    <span class="Normal">Hello World!</span>
                
  Adding Support for an Edit Page

If your module has an edit page, you can also use the DesktopModuleTitle to render the edit item link next to the module's title. EditText is the text to display in the link, and EditUrl is the path of the edit page, relative to the portal's root directory.

 
    <%@ Control Inherits="ASPNET.StarterKit.Portal.PortalModuleControl" %>
    <%@ Register TagPrefix="Portal" TagName="Title" Src="~/DesktopModuleTitle.ascx" %>

    <portal:title EditText="Edit" EditUrl="PortalModules/HelloWorld/EditHello.aspx" runat="server" />
    <span class="Normal">Hello World!</span>
                
  Creating a Module That Uses Data

Many portal modules display data from a database or XML file as a part of their rendered output. To display data, you load and bind it just as you would for a regular ASP.NET User Control. Here's a typical example using the Northwind SQL database.

 
    <%@ Control Inherits="ASPNET.StarterKit.Portal.PortalModuleControl" %>
    <%@ Register TagPrefix="Portal" TagName="Title" Src="~/DesktopModuleTitle.ascx" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>

    <script language="C#" runat="server">

        void Page_Load(Object sender, EventArgs e) {

            SqlConnection connection = new SqlConnection("server=localhost;uid=sa;pwd=;database=northwind");
            SqlCommand command = new SqlCommand("SELECT TOP 10 ProductName, UnitPrice FROM Products ORDER BY UnitPrice DESC", connection);

            connection.Open();
            
            grid1.DataSource = command.ExecuteReader(CommandBehavior.CloseConnection);
            grid1.DataBind();
        }

    </script>

    <portal:title runat="server" />

    <asp:DataGrid id=grid1 Cssclass="Normal" ShowHeader="false" BorderWidth="0" runat="server"/>
                
 

Adding a Custom Module to the Admin Tool
To add a module to the portal, simply access the Portal Admin Tool. It contains GUI support for dynamically loading your new module into the portal system.