Mobile Web Parts Pages and Adapters
Applies to: SharePoint Foundation 2010
This topic provides an overview of the SharePoint Foundation adapter framework for rendering Web Parts on mobile devices.
Mobile Adaption in SharePoint Foundation
Developers can make Web Part pages on SharePoint Foundation Web sites accessible to mobile devices using a variation of the mobile adapter system of Microsoft ASP.NET 3.5. The mobile adaption system in SharePoint Foundation is basically the same:
When a Web Part page is requested, the Web front-end server detects, from the request header, what kind of device is making the request.
If a mobile device is making the request, ASP.NET looks up each Web Part on the requested page in the compat.browser file to see what mobile adapter, if any, is associated with it.
For each of the events, Init, Load, PreRender, and UnLoad(); if a Web Part has a mobile adapter, then the adapter’s handler for the event is called rather than the Web Part’s own handler, although typically the adapter’s handler will call the Web Part’s handler as part of its logic.
The implementation, in SharePoint Foundation, of the adapter’s handlers for the four events checks to see if the current page is a WebPartMobilePage object. If it is, then the runtime calls the corresponding On*ForMobile method: OnLoadForMobile(EventArgs), OnInitForMobile(EventArgs), OnPreRenderForMobile(EventArgs), or OnUnloadForMobile(EventArgs).
For more information about the Microsoft ASP.NET 3.5 mobile adaption system, see Architectural Overview of Adaptive Control Behavior, Browser Definition File Schema (browsers Element), and System.Web.UI.Adapters.ControlAdapter.
Programming the SharePoint Foundation Mobile Adaption Framework
The SharePoint Foundation framework for mobile adapters is actually simpler to develop against than the Microsoft ASP.NET 3.5 mobile adaption system. As with the Microsoft ASP.NET 3.5 system, you will create a mobile adapter control for every Web Part that you want to be accessible to mobile devices, and you will map that adapter to the Web Part whose rendering it adapts in the compat.browser file.
But there are some ways in which developing with the SharePoint Foundation framework differs from mobile adapter development with Microsoft ASP.NET 3.5. For the most part these differences are needed to conform to the security model of SharePoint Foundation:
Your adapter class derives from Microsoft.SharePoint.WebPartPages.WebPartMobileAdapter instead of directly from System.Web.UI.Adapters.ControlAdapter.
Your adapter class must be registered as a Safe Control. For more information about how to do this, see Working with Web.config Files.
You do not override the Render(HtmlTextWriter) method inherited from ControlAdapter. Instead, you override one or both of the methods CreateControlsForSummaryView() and CreateControlsForDetailView().
You do not override the OnLoad(EventArgs), OnInit(EventArgs), OnPreRender(EventArgs), and OnUnload(EventArgs)methods that Microsoft.SharePoint.WebPartPages.WebPartMobileAdapter inherits from ControlAdapter. Instead, if you need additional logic for any of these events, you override one or more of the special SharePoint-secure replacement methods of Microsoft.SharePoint.WebPartPages.WebPartMobileAdapter: OnLoadForMobile(EventArgs), OnInitForMobile(EventArgs), OnPreRenderForMobile(EventArgs), and OnUnloadForMobile(EventArgs).
Important
See the reference topics for these four methods for important notes about how to override them.
The mobile-accessible Web Part pages are objects of the class WebPartMobilePage; but you don’t create them. When a mobile device user navigates to a Web Part page that contains Web Parts that have been adapted for mobile devices, a WebPartMobilePage object is created by the runtime and returned to the mobile device.
Each Web Part page, that contains Web Parts that have been adapted for mobile devices, has a corresponding application page where the visibility and order of the adapted Web Parts can be set. These pages are objects of the type WebPartMobileSettingPage and they are also created at runtime when a user navigates to one (usually be clicking a button on the ribbon of a Web Part page), so you do not create these objects either.
See Also
Reference
System.Web.UI.Adapters.ControlAdapter
Microsoft.SharePoint.WebPartPages.WebPartMobileAdapter
Concepts
Other Resources
Architectural Overview of Adaptive Control Behavior
Browser Definition File Schema (browsers Element)