动态LinkBut​​ton不再触发

时间:2016-08-16 15:18:13

标签: c# asp.net sharepoint-2013

我们有一个Sharepoint 2013项目。抽屉内容Web部件可以添加到页面并可以创建页面。问题是当您单击“删除项目链接按钮”时,不再在抽屉中删除。这是构建抽屉的代码:

protected HtmlGenericControl BuildDisplayContent()
        {
            Items.Sort();

            var container = new HtmlGenericControl("div");
            container.Attributes["class"] = "drawers drawers-multiple-levels";

            foreach (var contentItem in Items)
            {
                var drawerGroup = new HtmlGenericControl("div");
                drawerGroup.Attributes["class"] = "drawer-group";

                //subheader
                var subheaderWrapper = new HtmlGenericControl("div");
                subheaderWrapper.Attributes["class"] = "subheader-wrapper";

                var subheaderContainer = new HtmlGenericControl("div");
                subheaderContainer.Attributes["class"] = "subheader-container";

                var subheaderH3 = new HtmlGenericControl("h3");
                subheaderH3.Attributes["class"] = "subheader";
                subheaderH3.InnerHtml = contentItem.Header;

                subheaderContainer.Controls.Add(subheaderH3);
                subheaderWrapper.Controls.Add(subheaderContainer);
                drawerGroup.Controls.Add(subheaderWrapper);

                //drawer content
                var drawer = new HtmlGenericControl("div");
                drawer.InnerHtml = contentItem.Content;

                if (contentItem.Children == null || contentItem.Children.Count == 0)
                {
                    drawer.Attributes["class"] = "drawer";
                }
                else
                {
                    drawer.Attributes["class"] = "drawer drawer-with-subdrawers";

                    //fill child controls
                    contentItem.Children.Sort();

                    foreach (var child in contentItem.Children)
                    {
                        var childSubheaderH4 = new HtmlGenericControl("h4");
                        childSubheaderH4.Attributes["class"] = "subheader-second-level text-ca";
                        childSubheaderH4.InnerHtml = child.Header;
                        drawer.Controls.Add(childSubheaderH4);

                        var childDrawer = new HtmlGenericControl("div");
                        childDrawer.Attributes["class"] = child.IsTwoColumn ? "drawer drawer-second-level two-column" : "drawer drawer-second-level";
                        childDrawer.InnerHtml = child.Content;
                        drawer.Controls.Add(childDrawer);
                    }
                }

                drawerGroup.Controls.Add(drawer);

                var drawerBottom = new HtmlGenericControl("div");
                drawerBottom.Attributes["class"] = "drawer-bottom";

                drawerGroup.Controls.Add(drawerBottom);
                container.Controls.Add(drawerGroup);
            }

            return container;
        }

在OnLoad方法中调用此方法来构建抽屉内容。

点击事件:

void DeleteButton_Click(object sender, EventArgs e) {
            var button = (LinkButton)sender;
            var path = button.Attributes["ItemPath"].Split('-');

            if(path.Length == 1) {
                items.RemoveAt(Convert.ToInt32(path[0]));

                var c = 0;
                foreach (var item in items)
                    item.Ordinal = c++;

            } else if(path.Length == 2) {
                ((DrawerContentItem)Items[Convert.ToInt32(path[0])]).Children.RemoveAt(Convert.ToInt32(path[1]));

                var c = 0;
                foreach (var item in ((DrawerContentItem)Items[Convert.ToInt32(path[0])]).Children)
                    item.Ordinal = c++;
            }

            try
            {
                var storageKey = Manager.GetStorageKey(this);
                Manager.SaveChanges(storageKey);
            }
            catch (Exception ex)
            {
                var child = new Label();
                child.Text = ex.Message;
                this.Controls.Add(child);
            }

            BuildEditContent(control.BodyContentEdit.Controls);
        }

我们一直试图找出可能导致其停止工作的原因。任何想法都将不胜感激。

0 个答案:

没有答案