Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

UserControl in AdditionalPageHead breaking Minimal Download Strategy (MDS)

$
0
0

I need to create a user control to display on every SharePoint page, but it is causing MDS to failover and reload the page on team sites. How do I decorate or program my class so that MDS keeps working, likehttps://msdn.microsoft.com/en-us/library/office/dn456543.aspx says it should?

Here's a simple example. I created an empty SharePoint 2013 project as a farm solution and added a user control to it called CountdownControl.ascx and it's corresponding Elements.xml file, like so:

<Control Id="AdditionalPageHead" Sequence="90" ControlSrc="~/_ControlTemplates/15/Countdown/CountdownControl.ascx" />

Then I added an ASP.NET Label to the .ascx file, and then set the code-behind file like this:

[assembly: Microsoft.SharePoint.WebControls.MdsCompliantAttribute(IsCompliant = true)]
namespace Countdown.ControlTemplates.Countdown
{
    [Microsoft.SharePoint.WebControls.MdsCompliant(true)]
    public partial class CountdownControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime Christmas = new  DateTime(DateTime.Today.Year, 12, 25, 0, 0, 1);
            if (DateTime.Now.CompareTo(Christmas) > 0) Christmas = Christmas.AddYears(1);
            int daysLeft = (Christmas - DateTime.Now).Days;
            Label1.Text = "Only " + daysLeft.ToString() + " more " + (daysLeft == 1 ? "day" : "days") + " until Christmas!";
        }
    }
}

When I deploy this simple example to a team site it works...sort of. It adds a line at the top of the page of course, but pages in a team site (with the Minimal Download Strategy feature activated) now failover and cause the page to reload twice, the second time without the /start.aspx# in the URL. Slower, and with an annoying page flash.

Showing the days left until Christmas isn't the real requirement, it just makes a good example. What else do I need to do to keep MDS happy with a user control?


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>