自定义Web控件html渲染

时间:2014-05-05 13:19:11

标签: c# umbraco

这是我的代码,我创建了我的custum radiobuttonlist。它的工作原理但是......看看代码们。我正在使用umbraco和C#

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.member;
using System.Web.Security;
using umbraco.cms.businesslogic.web;
using System.Collections;

namespace RadioButtonList
{

    [DefaultProperty("Text")]
    [ToolboxData("<{0}:RadioButtonList runat=server></{0}:RadioButtonList>")]
    public class RadioButtonList : System.Web.UI.WebControls.RadioButtonList
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]

        private void populate()

    {
        foreach (umbraco.cms.businesslogic.Dictionary.DictionaryItem d in umbraco.cms.businesslogic.Dictionary.getTopMostItems)
        {
            if (d.hasChildren)
            {
                foreach (umbraco.cms.businesslogic.Dictionary.DictionaryItem d1 in d.Children)
                {
                    if (d1.hasChildren)
                    {
                        if (d1.Value(1) == "Target Groups")
                        {
                            SortedList list = new SortedList();
                            foreach (umbraco.cms.businesslogic.Dictionary.DictionaryItem d2 in d1.Children)
                            {
                                string translation;
                                int lang = umbraco.library.GetCurrentDomains(umbraco.presentation.nodeFactory.Node.GetCurrent().Id)[0].Language.id;
                                translation = "";
                                translation = new umbraco.cms.businesslogic.Dictionary.DictionaryItem(d2.key).Value(lang);

                                list.Add(translation, d2.key);



                            }
                            this.DataSource = list;
                            this.DataValueField = "value";
                            this.DataTextField = "key";
                            this.DataBind();


                        }

                    }
                }

            }
        }
    }


        protected override void OnPreRender(EventArgs e)

        {

            base.OnPreRender(e);

            populate();

        }

    }

它有效我可以获得新的Web控件但我想“控制”渲染html。我的RadioButtonList呈现一个跨度,但我不想要它导致它创建一些问题。我已经尝试了这个

protected override void Render(HtmlTextWriter writer)
{
RenderContents(writer);
}

但是当我使用它时,我的radiobuttonlist消失了,我再也看不到了。我真的需要帮助,因为我是第一次使用custum服务器控件。

1 个答案:

答案 0 :(得分:0)

您需要在其上设置RepeatLayout Property。除了Flow之外的任何东西都会消除这个范围,但这取决于你想用什么价值替换它。