在MOSS模板页中添加用户空间

在模板页中添加UserControl基本上有两种方法,一种是通过Feature将用户控件在MOSS中注册,通过DelegateControl在模板页中使用,另一种是把自己的用户控件也放在controltemplates目录下,通过在模板页中注册来使用UserControl.

编写用户控件

编写Moss使用的用户控件与普通用户控件唯一的区别是,引用的程序集应为GAC中的程序集,当然把程序集放在80目录下的Bin下也可以,但不推荐。

如:<%@ Control Language="C#" AutoEventWireup="true" Inherits="SharePoint.WebControls.LoginControl, SharePoint.LoginControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fdccb1101be1fce1" %>

部署用户控件

 

方法一:通过Feature将用户控件在MOSS中注册

  • 复制ascx文件到ControlTemplates
  • 编写feature文件

如:

Feature.xml

<?xml version="1.0" encoding="utf-8" ?>

<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->

<Feature Id="{47C45515-8B39-4567-9B2D-CB7B13B84ADC}"

Title=" 用户登录控件"

Description="$Resources:BasicSearch_Feature_Description;"

DefaultResourceFile="spscore"

Version="12.0.0.0"

Scope="Site"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest Location="Controls.xml"/>

</ElementManifests>

</Feature>

 

Controls.xml

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Control

Id="SharePointLoginControl"

Sequence="50"

ControlSrc="~/_ControlTemplates/LoginControl.ascx" >

</Control>

</Elements>

  • 安装、激活feature

     

    复制feature文件到template\feature\loginControl

    运行如下命令:

    @set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%

    stsadm -o installfeature -name LoginControl -force

    stsadm -o activatefeature -name LoginControl -url %1

     

  • 使用用户控件

<SharePoint:DelegateControl runat="server" ControlId="SharePointLoginControl"/>

需要注意的是,这里的ControlId与Feature中注册的Control Id要一致。

方法二:在模板页中使用用户控件

  1. 复制ascx文件到ControlTemplates
  2. 在模板页中注册程序集引用

<%@ Register Tagprefix="LoginControl" Namespace="SharePoint.WebControls"

Assembly="SharePoint.LoginControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fdccb1101be1fce1" %>

  1. 在模板页中注册控件

<%@ Register TagPrefix="wssuc" TagName="LoginControl" src="~/_controltemplates/LoginControl.ascx" %>

  1. 使用用户控件

<wssuc:LoginControl id="IdSafeBox" runat="server" EnableViewState="false"></wssuc:LoginControl>

 

以上两种方式是目前总结的结果,以后可能会有更多种方式,很显然第二种方法用起来很方便。

原文地址:https://www.cnblogs.com/moonwebmast/p/1450913.html