演练:自定义移动表单上的项目标题

上次修改时间: 2011年2月2日

适用范围: SharePoint Foundation 2010

此演练演示如何通过实现自定义 RenderingTemplate 来自定义移动网页上字段的呈现方式。该示例演示如何在移动列表项的"显示"表单上自定义"通知"列表中某个项目的"标题"字段。有关在移动网页上自定义字段的步骤的概述,请参阅如何:自定义移动页上的字段呈现

移动页呈现系统 中所述,从页面上的控件开始的一系列调用最终将调用具有以下 ID 格式的 RenderingTemplate:MobileCustomListField_ListTypeID_FieldType_Field。

其中,ListTypeID 是当前列表类型的 ID 号(如 105)或 SPListTemplateType 枚举的值之一(如 Contacts)。FieldType 是字段的数据类型(如 Text 或 Number),Field 是字段名称(如 WorkPhone)。如果不存在具有该 ID 的 RenderingTemplate,则使用 ID 为 MobileDefaultListField 的 RenderingTemplate

在 Microsoft SharePoint Foundation 中,没有 ID 为 MobileCustomListField_Announcements_Text_Title 的 RenderingTemplate。在本演练中,您将在移动显示表单上为"通知"列表中的项目创建一个替代该项目的模板。

自定义通知项的标题字段

  1. 在 Microsoft Visual Studio 中,创建一个"空白 SharePoint 项目"。使其成为服务器场解决方案,而不是沙盒解决方案。

  2. 向 TEMPLATE\ControlTemplates 中添加一个"SharePoint 映射文件夹"。

  3. 右键单击此新文件夹,并添加一个 SharePoint"用户控件"。为该 .ascx 文件命名,使其与其他解决方案提供程序的名称区分开;例如 ContosoMobileRenderingTemplates.ascx。Visual Studio 会自动将该文件添加到 SharePoint 解决方案清单中,并将其设置为部署到 %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\ControlTemplates。

    提示提示

    不要通过右键单击"解决方案资源管理器"中的项目 来添加"用户控件"。当通过这种方式添加"用户控件"时,Visual Studio 会将其放在 TEMPLATE\ControlTemplates 的子文件夹中,如果该控件未移动,Visual Studio 会将其部署到 %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\ControlTemplates 的相应子文件夹中。不会加载子文件夹中的移动呈现模板。

  4. 删除 .ascx.cs 和 .ascx.designer.cs(或 .ascx.vb 和 .ascx.designer.vb)文件。此项目不需要它们。

  5. 将 .ascx 文件的整个指令部分替换为以下标记:

    <%@ Register TagPrefix="GroupBoardMobile"   Namespace="Microsoft.SharePoint.Applications.GroupBoard.MobileControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#"   %> 
    <%@ Assembly Name="Microsoft.SharePoint, Version=14.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=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
    <%@ Register TagPrefix="SPMobile" Namespace="Microsoft.SharePoint.MobileControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
    <%@ Register TagPrefix="WPMobile" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
  6. 在指令下,添加一个 RenderingTemplate,并为其分配运行时要查找的 ID:MobileCustomListField_Announcements_Text_Title。

    <SharePoint:RenderingTemplate RunAt="Server" ID="MobileCustomListField_Announcements_Text_Title" >
    
    </SharePoint:RenderingTemplate>
    
  7. RenderingTemplate 元素中,定义一个具有 Label 子控件的 Template 元素。按如下所示设置标签的 Text 属性:

    <Template>
      <mobile:Label Text="Title field in Announcements List" 
        RunAt="Server" />
    </Template>
    
  8. 在"生成"菜单上选择"部署解决方案"。这将自动保存 .ascx 文件,将其部署到 %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATES\ControlTemplates,并回收 Web 应用程序,以便重新加载该文件夹中的所有 .ascx 文件。

  9. 使用您的设备或仿真程序导航到至少包含一项的"通知"列表。单击某个项目以显示它。您应该会看到下面的图像中显示的新标题:

自定义移动显示项目表单

请参阅

任务

如何:自定义移动页上的字段呈现

概念

移动页的布局和分页

移动页呈现系统