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

WSS 3.0 SDK 技術詳解:如何定制 Mobile 頁面中的欄位渲染——RenderingTemplate 機制與部署全攻略

     編輯:關於.NET

Mobile 欄位渲染定制流程概覽

Mobile 頁面透過 SPMobileListFieldSelector 發起鏈式調用,依目前列表類型與欄位決定套用的 RenderingTemplate。開發者可透過部署同 ID 的自訂模板覆寫預設渲染。

RenderingTemplate ID 命名規則與解析邏輯

搜尋 ID 格式:MobileCustomListField_{ListTypeID}_{FieldType}_{Field}

重要:若欄位顯示名稱含空格/標點,系統產生的內部名稱將包含編碼字元(如 _x0020_),導致 ID 無法匹配,**此類欄位無法透過此機制定制渲染**。

內建 RenderingTemplate 清單

WSS 安裝後預載於 MobileDefaultTemplates.ascx:

  • MobileCustomListField_Contacts_Text_WorkPhone
  • MobileCustomListField_Contacts_Text_HomePhone
  • MobileCustomListField_Contacts_Text_CellPhone
  • MobileCustomListField_Contacts_Text_Email
  • MobileCustomListField_PictureLibrary_Computed_ImageSize
  • MobileCustomListField_Posts_DateTime_PublishedDate
勿修改 MobileDefaultTemplates.ascx。可建立同 ID 新模板覆寫,但有風險:可能破壞相依原模板的其他方案。載入順序:內建 → 自訂(字母序後者勝出),同檔案重複 ID 皆不載入。

定制步驟標準化流程

  1. 建立 .ascx 使用者控制項檔,置於 \12\TEMPLATE\CONTROLTEMPLATES。
  2. 加入頁面指示詞註冊必要命名空間(mobile、SharePoint、SPMobile)。
  3. 宣告 <SharePoint:RenderingTemplate>,ID 依命名規則設定。
  4. <Template> 內直接放置可渲染控制項(如 <mobile:Label>),或參考繼承 SPMobileBaseFieldControl 的自訂控制項標籤。
  5. 儲存檔案,執行 iisreset 生效。

範例:公告列表 Title 欄位自訂渲染

<SharePoint:RenderingTemplate RunAt="Server" ID="MobileCustomListField_Announcements_Text_Title">
  <Template>
    <mobile:Label Text="Title field in Announcements List" RunAt="Server" />
  </Template>
</SharePoint:RenderingTemplate>

進階:巢狀 RenderingTemplate

可在 <Template> 內參考其他 RenderingTemplate(透過 SPMobileComponent):

<SharePoint:RenderingTemplate ID="Mobile_104_View_Navigation" RunAt="Server">
  <Template>
    <mobile:Link Text="ASP.NET Website" NavigateUrl="https://www.asp.net" RunAt="Server" />
    <mobile:Label RunAt="Server" Text="" BreakAfter="True" />
    <SPMobile:SPMobileComponent RunAt="Server" TemplateName="Mobile_Default_View_Navigation" />
  </Template>
</SharePoint:RenderingTemplate>

此技巧可組合預設渲染與自訂內容,保留原有導航列同時加入新連結。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved
佔位符來源與取值
ListTypeID列表範本 ID(如 104)或 SPListTemplateType 列舉值(如 Announcements、Contacts)。
• 站台定義中列表:Onet.xml List@Type
• UI 建立列表:以建立時選擇的列表範本 ID 為準
FieldTypeSPFieldType 列舉值(Text、Number、DateTime...)或 fldtypes*.xml 中 <Field Name="TypeName"> 定義的自訂欄位類型名稱。
Field欄位**內部名稱**(非顯示名稱)。
• Schema.xml 定義:Field@Name
• UI 建立欄位:SPField.InternalName(由顯示名稱自動編碼,含空格/標點時無法對應,故無法定制)。