Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I had gone the route of creating a placeholder on the aspx page and then doing:

myPlaceHolder.Controls.Add(myTaxonomyControl);

but for some reason this doesn't do anything. No error and no control. Do I need to do anything special to add this type of control to a page?

share|improve this question

2 Answers 2

This is the code I use:

var taxField = field as TaxonomyField; // the SPField the control should bind to
var session = new TaxonomySession(field.ParentList.ParentWeb.Site);
var store = session.TermStores[0];
var termSet = store.GetTermSet(taxField.TermSetId);
var taxonomyControl = new TaxonomyWebTaggingControl();
taxonomyControl.IsMulti = taxField.AllowMultipleValues;
taxonomyControl.IsAddTerms = termSet.IsOpenForTermCreation;
if (termSet.IsOpenForTermCreation)
{
  taxonomyControl.AllowFillIn = true;
}
taxonomyControl.TermSetId.Add(store.Id);
taxonomyControl.ID = "fld_" + taxField.InternalName;
taxonomyControl.FieldName = taxField.Title;
taxonomyControl.FieldId = taxField.Id.ToString();
taxonomyControl.SSPList = taxField.SspId.ToString();
taxonomyControl.AnchorId = taxField.AnchorId;
taxonomyControl.TermSetList = taxField.TermSetId.ToString();
if (!Page.IsPostBack)
{
  if (Item[taxField.InternalName] != null)
  {
    taxonomyControl.Text = Item[taxField.InternalName].ToString();
  }
}
fieldPanel.Controls.Add(taxonomyControl);
share|improve this answer
    
Where do you create the field? Some code seems to be missing –  Eric Herlitz Nov 12 at 14:39

You need to bind the term set to the TaxonomyWebTaggingControl so that it allows you to pick and display terms. See link below:

http://blog.bugrapostaci.com/2010/09/23/taxonomywebtaggingcontrol-sharepoint/

and

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomywebtaggingcontrol.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.