首页 > 开发 > 综合 > 正文

Creating Custom Portal Modules

2024-07-21 02:16:39
字体:
来源:转载
供稿:网友
--------------------------------------------------------------------------------
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="aspnetportal.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="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 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 how to get the module's title from the portal framework, and render it consistently 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 an edit page, you can also use 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 is the path of the edit page, relative to the portal's root directory.


      <%@ 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, 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="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=;database=northwind")
            dim command as new sqldatasetcommand("select top 10 productname,
                unitprice from 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, you simply create an entry for it in the <moduledefinitions> section of the portal.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 admin tool itself.)

for example:
        <moduledefinitions>
            <moduledefinition name="helloworld" src="portalmodules/helloworld/helloworld.ascx"/>
        </moduledefinitions>
                

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表