1

I've been pulling my hair out with this. We have an implementation of bxslider in a SharePoint 2013 home page. This work was completed by my now departed collegue, so not my work, but .... it was finished and working.

Now though I get a runtime error when calling onSliderLoad callback function which calls slider.goToNextSlide();

Extract from Debug Output window VS: 0x800a138f - JavaScript runtime error: Unable to get property 'goToNextSlide' of undefined or null reference

I've pretty much ruled out a code change because I've reverted the source code back months and also restored a very old snapshot into the virtual SharePoint server. These all still experience the same new issue. I also tried this trick on our staging server which hasn't had any newly released code for a while. This host is now experiencing the same issue. Only thing I can think is that there is a external change which is causing this issue, but what I have no idea.

I get different errors from Firebug and IE10 (It's SharePoint you have to test and debug in IE as well ;-))

Firebug Errors

enter image description here

Extract from FeedsRotator.ascx (Webpart on Home.aspx)

var slider= $('#slider2').bxSlider({
        auto: true,           
        controls: false,
        pager:false,
        pause: 10000,
        slideWidth: (sir ? sirina:300),
        slideHeight: 450,
        randomStart: true,
        autoHover: true,
        onSliderLoad: function (currentIndex) {
        slider.goToNextSlide(); //This is line 1024
        },

Extract from BxSlider.css

#slider1 {
margin:0;
padding:0;
}

.bx-wrapper {
position: relative;
margin: 10px;
padding: 0;
*zoom: 1;
}

.bx-wrapper img {
max-width: 100%;
display: block;
}

Forgot to say we're using jquery 1.9.1.

Matthew R
  • 1,038
  • 11
  • 15
  • Was your departed colleague's home directory deleted two days ago? – stark Dec 17 '13 at 17:45
  • Umm, that's an interesting question. Her laptop got reimaged the other day for redistribution to another colleague, but it had been offline ever since she left and was reimaged onto a new disk because ironically her disk died the week she left. I've just enquired about her users network share was removed, but I doubt she used it. – Matthew R Dec 18 '13 at 10:08

1 Answers1

0

So, I was completely barking up the wrong tree with the clientside code. It was infact that the Annoucements List items which populate the news slider had expired 5 days ago.

news list item 1 It was therefore the server side code on the webpart which queries the list which wasn't returning any data:

string Qry = " <Where><Geq><FieldRef Name='Expires' /><Value IncludeTimeValue='FALSE' Type='DateTime'>{0}</Value></Geq></Where>";

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!((Page)System.Web.HttpContext.Current.CurrentHandler).IsPostBack)
        {
            DisplayAnnouncements();
        }
    }
    private void DisplayAnnouncements()
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                {
                    SPList list = web.Lists["Announcements"];
                    SPQuery query = new SPQuery();
                    query.RowLimit = 10;
                    query.Query = string.Format(Qry, DateTime.Now.ToString("yyyy-MM-dd"));


                    rep1.DataSource = list.GetItems(query).GetDataTable();
                    rep1.DataBind();

                }
            }
        }
              );
    }

So now I have to decide how to handle this

Option 1 (find the most recently expired announcements):

private void DisplayAnnouncements()
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                {
                    SPList list = web.Lists["Announcements"];
                    SPQuery query = new SPQuery();
                    query.RowLimit = 10;
                    DateTime queryDate = DateTime.Now;

                    query.Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd"));

                    while (list.GetItems(query).Count == 0 && queryDate > new DateTime(2000, 1, 1)) //Stop an infinitive loop where list is empty
                    {
                        TimeSpan oneDay = new TimeSpan(1, 0, 0, 0);
                        queryDate = queryDate - oneDay;
                        query = new SPQuery() { Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd")) };
                    }

                    rep1.DataSource = list.GetItems(query).GetDataTable();
                    rep1.DataBind();

                }
            }
        }
              );
    }

Option 2 (Display No News)

private void DisplayAnnouncements()
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                {
                    bool oldAllowUnsafeUpdates = web.AllowUnsafeUpdates; 
                    web.AllowUnsafeUpdates = true; 
                    web.Update(); 

                    SPList list = web.Lists["Announcements"];
                    SPQuery query = new SPQuery();
                    query.RowLimit = 10;
                    DateTime queryDate = DateTime.Now;

                    query.Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd"));

                    if (list.GetItems(query).Count == 0)
                    {
                        SPListItem noNewsListItem = list.AddItem();

                        noNewsListItem["Title"] = "NoCurrentNews";
                        noNewsListItem["MainDisplayImage"] = "<img src=\"/sites/OMGIntranet/SiteAssets/NO-CURRENT-NEWS-STORIES.jpg\"></img>";
                        noNewsListItem["Expires"] = DateTime.MaxValue;

                        noNewsListItem.Update();
                    }

                    rep1.DataSource = list.GetItems(query).GetDataTable();
                    rep1.DataBind();

                    web.AllowUnsafeUpdates = oldAllowUnsafeUpdates;
                }
            }
        }
              );
    }
Matthew R
  • 1,038
  • 11
  • 15