简体   繁体   English

自定义Web控件html渲染

[英]custom web control html render

This is my code , i created my custum radiobuttonlist. 这是我的代码,我创建了custum单选按钮列表。 And it works but.. take a look at the code guys. 它有效,但是..看一下代码专家。 Im using umbraco and C# 我正在使用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();

        }

    }

It works i can get the new web control but i want to "control" the render html. 它可以工作,我可以获取新的Web控件,但是我想“控制”渲染HTML。 My RadioButtonList renders a span but i dont want it cause it create some issues. 我的RadioButtonList呈现了一个范围,但是我不希望它引起它产生一些问题。 I already tryed this 我已经尝试过了

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

But when i use this my radiobuttonlist disappears and i cant see it anymore. 但是当我使用它时,我的单选按钮列表消失了,我再也看不到它了。 I really need help cause im new to this and its my 1st time using custum server controls. 我真的需要帮助,这是我第一次使用custum服务器控件。

You need to set the RepeatLayout Property on it. 您需要在其上设置RepeatLayout属性 Anything but Flow will get rid of the span, but it depends what you want to replace it with as to what value you want. 除了Flow之外,任何东西都将摆脱该范围,但是这取决于您要替换为什么值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM