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

WSS 3.0 SDK 實戰演練:在 Mobile 顯示表單定制列表項標題——以 RenderingTemplate 覆寫預設渲染

     編輯:關於.NET

演練目標

示範如何透過自訂 RenderingTemplate 控制項,在 Mobile 顯示頁面(DispForm)覆寫**公告列表**的 **Title 欄位**渲染,將標題文字替換為自訂靜態文字。

Mobile 欄位渲染機制回顧

Mobile 頁面透過 SPMobileListFieldSelector 模板選擇器,依列表類型與欄位決定使用哪個 RenderingTemplate。搜尋 ID 格式:

MobileCustomListField_{ListTypeID}_{FieldType}_{FieldInternalName}
  • ListTypeID:列表範本 ID(如 104)或 SPListTemplateType 列舉值(如 Announcements)。
  • FieldType:SPFieldType 列舉值(如 Text、Number)。
  • FieldInternalName:欄位內部名稱(Title 欄位為 Title)。

找不到時回退至 MobileDefaultListField。WSS 內建無 MobileCustomListField_Announcements_Text_Title,故可自行建立覆寫。

建立自訂 RenderingTemplate:AnnouncementsItemDisplayPageTitleField.ascx

  1. 建立 UTF-8 文字檔,命名 AnnouncementsItemDisplayPageTitleField.ascx,置於:
    Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
  2. 加入必要指示詞與命名空間註冊:
    <%@ Control Language="C#" %>
    <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
    <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="SPMobile" Namespace="Microsoft.SharePoint.MobileControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
  3. 定義 RenderingTemplate,ID 為目標搜尋 ID:
    <SharePoint:RenderingTemplate RunAt="Server" ID="MobileCustomListField_Announcements_Text_Title">
      <Template>
        <mobile:Label Text="Title field in Announcements List" RunAt="Server" />
      </Template>
    </SharePoint:RenderingTemplate>
  4. 儲存檔案,執行 iisreset 重新載入模板。
  5. 若使用模擬器,清除 IE 暫存檔。

驗證結果

以 Mobile 裝置/模擬器瀏覽公告列表項目顯示頁面,Title 欄位將顯示 **「Title field in Announcements List」** 而非原始標題內容。
自訂標題渲染截圖

核心觀念總結

  • Mobile 渲染完全由 RenderingTemplate 控制,零程式碼編譯即可覆寫 UI。
  • ID 命名慣例是關鍵:MobileCustomListField_{ListType}_{FieldType}_{InternalName}。
  • .ascx 置於 CONTROLTEMPLATES 目錄,iisreset 生效。
  • 此為「宣告式覆寫」最簡形式,進階邏輯需結合自訂控制項(參考下一篇演練)。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved