Adding Audience Targeting to your Publishing Page

posted Feb 11, 2010, 9:26 PM by Nick del Rosario   [ updated Mar 31, 2010, 8:06 PM ]
Audience Targeting  is a bit confusing when it comes to a SharePoint publishing page. At first glance you would think that there would be a control handy for you to drop onto the page and bind to the field. Although once you get into the nitty gritty you come to find that Hey! Where is the control I'm looking for?
First attempt was to look in the following namespace:
- Microsoft.SharePoint.WebControls (No success)
Next attempt:
- Microsoft.SharePoint.Publishing.WebControls (Again no success)
Next thought was what control does Out of the box SharePoint use to select audience targeting? So my next steps were to look at the built in edit form aspx page used by SharePoint and follow the trail to the actual control. And the trail led to the following control which I added to my page:
Steps to add the Audience Targeting control to your page:
1) Add the page directive tags mapping to the proper namespace and assembly:
<%@ Register TagPrefix="OfficeWebControls" Namespace="Microsoft.Office.Server.WebControls.FieldTypes"
    Assembly="Microsoft.Office.Server, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
2) Add the Audience Targeting Control (SPFieldTargetToControl)
<OfficeWebControls:SPFieldTargetToControl ID="Audience" runat="server"  FieldName = "Audience" AudienceTypes="GlobalAudience"/>
Upon adding these field and recompiling the project and loading my publishing page, viola my page now has audience targeting! 
Audience Targeting Control
Audience Targeting Control Dialog