Пример #1
0
        public void NamingContainers_EnsureControlHasID_GenerateUniqueID()
        {
            var page = new RedwoodView();
            page.SetValue(Internal.UniqueIDProperty, "c0");

            var head = new HtmlGenericControl("head");
            head.SetValue(Internal.UniqueIDProperty, "c1");
            page.Children.Add(head);

            var title = new HtmlGenericControl("title");
            title.SetValue(Internal.UniqueIDProperty, "c2");
            head.Children.Add(title);

            var body = new HtmlGenericControl("body");
            body.SetValue(Internal.UniqueIDProperty, "c3");
            page.Children.Add(body);

            var div1 = new HtmlGenericControl("div");
            div1.SetValue(Internal.UniqueIDProperty, "c4");
            body.Children.Add(div1);

            var div2 = new HtmlGenericControl("div");
            div2.SetValue(Internal.UniqueIDProperty, "c5");
            div2.SetValue(Internal.IsNamingContainerProperty, true);
            body.Children.Add(div2);

            var div3 = new HtmlGenericControl("div");
            div3.SetValue(Internal.UniqueIDProperty, "c6");
            div2.Children.Add(div3);

            div3.EnsureControlHasId(true);
            div1.EnsureControlHasId(true);

            Assert.AreEqual("c4", div1.ID);
            Assert.AreEqual("c5_c6", div3.ID);
        }
Пример #2
0
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("css", "{ 'disabled': IsFirstPage() }");
            firstLi.Render(writer, context);

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsFirstPage() }");
            previousLi.Render(writer, context);

            // render template
            writer.WriteKnockoutDataBindComment("foreach", "NearPageIndexes");
            context.PathFragments.Push("NearPageIndexes[$index]");

            // render page number
            numbersPlaceholder.Children.Clear();
            HtmlGenericControl li;
            if (!RenderLinkForCurrentPage)
            {
                writer.AddKnockoutDataBind("visible", "$data == $parent.PageIndex()");
                li = new HtmlGenericControl("li");
                li.SetValue(Internal.IsDataContextBoundaryProperty, true);
                var literal = new Literal();
                literal.SetBinding(Literal.TextProperty, new ValueBindingExpression("_this + 1"));
                li.Children.Add(literal);
                numbersPlaceholder.Children.Add(li);
                li.Render(writer, context);

                writer.AddKnockoutDataBind("visible", "$data != $parent.PageIndex()");
            }
            writer.AddKnockoutDataBind("css", "{ 'active': $data == $parent.PageIndex()}");
            li = new HtmlGenericControl("li");
            li.SetValue(Internal.IsDataContextBoundaryProperty, true);
            var link = new LinkButton();
            link.SetBinding(ButtonBase.TextProperty, new ValueBindingExpression("_this + 1"));
            link.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("_parent.GoToPage(_this)"));
            li.Children.Add(link);
            numbersPlaceholder.Children.Add(li);
            li.Render(writer, context);

            context.PathFragments.Pop();
            writer.WriteKnockoutDataBindEndComment();

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsLastPage() }");
            nextLi.Render(writer, context);

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsLastPage() }");
            lastLi.Render(writer, context);
        }