首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

SharePoint WSS 3.0:自訂委派控制項 (Delegate Control) 實作教學

     編輯:關於.NET

前言

SharePoint 的委派控制項 (Delegate Control) 允許開發者以 Feature 方式替換頁面上的特定控制項 (如搜尋框、導覽列等),而不需修改母版頁。本文示範如何建立 Feature 取代預設的 SmallSearchInputBox 搜尋框圖示。

實作步驟

1. 複製內建 Feature 為基礎

複製 \TEMPLATE\FEATURES\ContentLightup 資料夾至:

Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\NewSearchBox

2. 修改 Feature.xml

更新 GUID (使用 guidgen.exe 產生)、標題、描述、範圍設為 WebApplication,並指向自訂控制項定義檔:

<?xml version="1.0" encoding="utf-8"?>
<Feature Id="{NEW_GUID}"
  Title="New Search Image"
  Description="Points at which third parties light up in content pages"
  Version="12.0.0.0"
  Scope="WebApplication"
  xmlns="https://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="controls\searcharea.xml" />
  </ElementManifests>
</Feature>

3. 修改 controls\searcharea.xml

指定要替換的委派控制項 ID (SmallSearchInputBox)、順序 (Sequence) 以及自訂使用者控制項 (.ascx) 路徑:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="https://schemas.microsoft.com/sharepoint/">
  <Control
    Id="SmallSearchInputBox"
    Sequence="100"
    ControlSrc="~/_controltemplates/mySearchArea.ascx">
    <Property Name="SearchTextToolTip">Search this site</Property>
    <Property Name="SearchImageToolTip">Go</Property>
  </Control>
</Elements>

4. 建立自訂使用者控制項

  1. 複製 \TEMPLATE\CONTROLTEMPLATES\SearchArea.ascx 至同目錄下,重新命名為 mySearchArea.ascx。
  2. 編輯 mySearchArea.ascx,尋找 <img> 標籤,將 src 屬性指向新圖片。測試時可使用內建圖片 (如 /_layouts/images/FOLDER.GIF) 替換原本的 gosearch.gif。

關鍵片段:

<img border='0' src="/_layouts/images/FOLDER.GIF" style='vertical-align: 1' ... />

5. 安裝與啟用 Feature

stsadm -o installfeature -filename NewSearchBox\feature.xml
stsadm -o activatefeature -filename NewSearchBox\feature.xml -url https://Server/Site/Subsite

6. 驗證結果

瀏覽該子網站,搜尋框右側的「前往」圖示即已替換為自訂圖片。

重點總結

  • 委派控制項替換透過 <Control> 元素的 Id、Sequence、ControlSrc 三屬性控制。
  • Sequence 數值越小優先權越高,若多個 Feature 針對同一控制項,最小者生效。
  • 自訂 .ascx 檔置於 _controltemplates 目錄,採用 ~/_controltemplates/ 相對路徑引用。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved