I was reading this link which provide a solution to a redirect problem inside my SharePoint enterprise wiki site collection:-


and to add the user control inside my page layout i did the following steps:-

1.i open the visual studio 2012, create a new SharePoint Farm Solution.

2.then i add a new User Control (Farm solution only) inside the Vs prodect.

3.under the user control i added the following code:-

using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint.WebControls;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace WikiPopUp.ControlTemplates.WikiPopUp
    [ToolboxData("<{0}:CustomValidationRequiredFieldsOnPage runat=server></{0}:CustomValidationRequiredFieldsOnPage>")]
    public class CustomValidationRequiredFieldsOnPage : WebControl
        protected override void CreateChildControls()

            if (SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
                bool arethere = AreThereAnyMissingRequiredFieldsOnPage();

                if (arethere)
                    //Provides an ASP.NET control that handles the Ribbon buttons controlling the state of a Microsoft SharePoint Server wiki or publishing page,
                    //such as the CheckInCheckOutButton or the PublishingButton.
                    SPPageStateControl baseParentStateControl = Page.Items[typeof(SPPageStateControl)] as SPPageStateControl;

                    //Publish button: SPListItem MissingRequiredFields checks this.FieldHasValue(link.Name, field);
                    //the field is empty (which is right) when the page is first created (MMD field is never filled in)
                    //when the field was once filled, saved and emptied the field in sp code still has the previous value and the check MissingRequiredFields succeeds
                    //after succeeding this check the page is validated (this.Page.Validate()) and this one fails which results SP validating the page as the Save button does

                    if (baseParentStateControl.HasError)
                        //this overwrites the previous PageErrorState
                        //and validates the page
                        //no popup anymore and status updates in yellow area
                    //there are missing fields at this listitem, but they're not on the page
                    //do nothing here, because the SerializedErrorState contains the navigate url to the Edit Properties page
                    //and a message pops up

        /// <summary>
        /// Check if required fields are missing which are present at the page
        /// </summary>
        /// <returns></returns>
        private static bool AreThereAnyMissingRequiredFieldsOnPage()
            foreach (Control control in SPContext.Current.FormContext.FieldControlCollection)
                //get the control type
                string type = control.GetType().Name;

                FieldTypes controlType = (FieldTypes)Enum.Parse(typeof(FieldTypes), type);

                switch (controlType)
                    case FieldTypes.TaxonomyFieldControl:
                        TaxonomyFieldControl tfc = control as TaxonomyFieldControl;
                        if (!tfc.IsValid)
                           return true;

            return false;

        enum FieldTypes
            DateTimeField, FieldValue, TextField, RichImageField, NoteField, RichHtmlField, PublishingScheduleFieldControl, TaxonomyFieldControl, BooleanField, ComputedField

4.then i deploy the farm solution.

5.i went to the central administration, and under the farm solutions i found the solution deployed globally.

so my question is how i can register the user control which i already deployed under the farm solution inside my page layout ? not sure what i should write exacly. i tried adding the following code inside my page layout:-

<%@ Register Tagprefix="MyControls" 
    Assembly="WikiPopUp.ControlTemplates, Version=, Culture=neutral, PublicKeyToken=******" %>

but i got the following error when i try opening the page:-

Sorry, something went wrong 
Could not load file or assembly 'WikiPopUp.ControlTemplates, Version=, Culture=neutral, PublicKeyToken=*****' or one of its dependencies. The system cannot find the file specified. 

can anyone advice please?


2 Answers 2


I think you just need to add your control to the safe controls section in your web.config. You can configure your VS project to do this for you. You should have a Module in your VS project, highlight this item and look at the properties window. You should see a Safe Control Entries property. Click the ellipsis in the box next to this property and it will bring up a popup window where you can add an entry for your control. You'll need to provide it with the Name, Assembly and Namespace of your control and set Safe to true. Save and redeploy your webpart and see if that does the trick. If not take a look at your web.config and make sure there was an entry added for your control.

  • i really got confused on how to use a user control. can you advice what do u mean by i should have a Module in my VS project ? and you said to re-deploy my web part, but i am not creating a web part. i created a farm solution containing a user control ? can you advice please ?
    – John John
    Sep 4, 2014 at 16:22
  • My apologies John. The things that you need to ensure are that the user control's assembly is being added to the GAC and that an entry is being added to the web.config's safe control section. If those two things are good then you should be able to add your register tag in your page layout and use your control. This link may help with configuring the VS project: stackoverflow.com/questions/8406037/…
    – Mike Lutge
    Sep 4, 2014 at 17:34
  • now i think i have deployed the farm solution which contains the user control correctly . now i need to reference the user control inside the page layout . but i am not sure how to do it ?. but is deploying my user control inside a farm solution the correct approach to follow?
    – John John
    Sep 4, 2014 at 22:17

i have applied the SP CU for september 2014, and my redirect problem has been solved . so now i do not need the workaround...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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