Creating Custom Portal Modules

Source: Internet
Author: User
Tags tagname
--------------------------------------------------------------------------------
A portal module combines some code and UI to present specific functionality to the user (for example, a threaded Discussio n) or render data, graphics and text, (for example, a "Sales by Region"). In addition, a portal module needs to know and the "interact with the" portal Framework to participate in the rendering, edit ING, 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 this inherits from the ASP Netportal.portalmodulecontrol class.

Hello World

For example, here's a simple "Hello World" Portal Module (helloworld.ascx).
<%@ control inherits= "Aspnetportal.portalmodulecontrol"%>

Hello world!


Using CSS Styles in Portal Modules

The portal Framework includes a stylesheet called Portal.css that are applied to all tabs in the portal. You can use the styles defined into Portal.css to make the appearance of your custom module consistent with the built-in MOD Ules. The most commonly used style is "Normal", which are applied to most text rendered by modules. Here we'll ' ve updated helloworld.ascx to use a style.
<%@ control inherits= "Aspnetportal.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 are want your module to display it's title like the standard portal modules, add the Portalmoduletitle user control to Your module. The Portalmoduletitle user control knows the "the" module ' s title from the Portal Framework, and render it consistent Ly with the rest of the portal.


<%@ control inherits= "Aspnetportal.portalmodulecontrol"%>
<%@ Register tagprefix= "Portal" tagname= "Title" src= ". /.. /portalmoduletitle.ascx "%>

<portal:title runat= "Server"/>
<span class= "Normal" >hello world!</span>


Adding Support for an Edit Page

If your module has a edit page, you can also with the Portalmoduletitle to render the edit item link next to the module ' s Title. EditText is the text to display in the link, and Editurl are the path of the edit page, relative to the portal ' s root direc Tory.


<%@ control inherits= "Aspnetportal.portalmodulecontrol"%>
<%@ Register tagprefix= "Portal" tagname= "Title" src= ". /.. /portalmoduletitle.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, your load and bind it just as you would for a regular asp.net the User control. Here ' s A typical example using the Northwind SQL database.


<%@ control inherits= "Aspnetportal.portalmodulecontrol"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<%@ Register tagprefix= "Portal" tagname= "Title" src= "Portalmoduletitle.ascx"%>

<script language= "VB" runat= "Server" >

Sub Page_Load (sender as Object, E as EventArgs)

Dim Connection as New SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=northwind")
Dim command as New sqldatasetcommand ("Select Top" ProductName,
UnitPrice from the products order by UnitPrice DESC ", connection)

Dim DataSet as New DataSet ()
Command. FillDataSet (DataSet, "products")

Grid1. DataSource = DataSet. Tables (0). DefaultView
Grid1. DataBind ()

End Sub

</script>

<portal:title runat= "Server"/>

<asp:datagrid ID=GRID1
Autogeneratecolumns= "false"
cssclass= "Normal"
Showheader= "false"
Borderwidth= "0"
runat= "Server" >

<property name= "Columns" >
<asp:boundcolumn datafield= "ProductName"/>
<asp:boundcolumn datafield= "UnitPrice" dataformatstring= "{0:c}"/>
</property>

</asp:DataGrid>




Adding a Custom Module to the Admin Tool
--------------------------------------------------------------------------------
To add a module to the Admin Tool, your simply create an entry for it <ModuleDefinitions> section of the Porta L.config file. (You'll need to edit the file directly there's is no support for modifying this part of the configuration file in the ADM In tool itself.)

For example:
<ModuleDefinitions>
<moduledefinition name= "HelloWorld" src= "Portalmodules/helloworld/helloworld.ascx"/>
</ModuleDefinitions>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.