Question

I am trying to follow the steps described inside the following link , which mainly require adding a web control and then reference it from a page layout:-

http://www.itidea.nl/index.php/what-about-you-must-fill-out-all-required-properties-before-completing-this-action-when-publishing-a-page/

But i need help in understanding how to create the mentioned web control and add it to a page layout ? Please note the i am using Visual studio 2012 + SharePoint 2013. Can anyone list the steps which i need to follow? Thanks for any help. Regards

EDIT

I follow these steps to deploy a user control.

  1. using Visual Studio 2012 , i added a new Farm solution.

  2. then inside the farm solution i added a new User Control(Farm Solution Only).

3.inside the user control i entered 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()
        {
            base.CreateChildControls();

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

                if (arethere)
                {
                    //SPPageStateControl:
                    //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
                        baseParentStateControl.EnsureItemSavedIfEditMode(false);
                    }
                }
                else
                {
                    //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;
                        }
                        break;
                    default:
                        break;
                }
            }

            return false;
        }

        enum FieldTypes
        {
            DateTimeField, FieldValue, TextField, RichImageField, NoteField, RichHtmlField, PublishingScheduleFieldControl, TaxonomyFieldControl, BooleanField, ComputedField
        }
    }
}
  1. i add a reference for the Sharepoint.taxnomy.

  2. then i deploy the solution to my site collection. and now i can see the new solution inside the farm solution under central administration.

but not sure if these are all the required steps to register the user control or still i need to do extra steps ?

Was it helpful?

Solution 2

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

OTHER TIPS

You can follow following steps:

In Solution Explorer, choose the project node. On the menu bar, choose Project, Add New Item. The Add New Item dialog box opens. In the Installed pane, choose the Office/SharePoint node. In the list of SharePoint templates, choose User Control (Farm Solution Only).

For more details:

http://blogs.msdn.com/b/kaevans/archive/2011/04/28/user-controls-and-server-controls-in-sharepoint.aspx

http://msdn.microsoft.com/en-in/library/ee231548.aspx

http://blogs.msdn.com/b/kaevans/archive/2011/04/28/user-controls-and-server-controls-in-sharepoint.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top