开发者

Adding Controls to Controls in codebehind

I'm trying to add a span, inside an anchor, inside a dd tag. for some reason this:

protected Control MakeDD() {
    var dd = new HtmlGenericControl("dd");
    var link = new HtmlGenericControl("a");
    var span = new HtmlGenericControl("span");

    link.Controls.Add(span);
    dd.Controls.Add(link);
    return dd;
}

only generates

<dd><a></a></dd>

instead of

<d开发者_运维问答d><a><span></span></a></dd>

how do I add controls to a control, then add that control to another control?


Dropping a panel on a page as the container and doing:

        protected void Page_Load(object sender, EventArgs e)
        {
            pnlTest.Controls.Add(MakeDD());
        }

emits the following on the page:

<div id="MainContent_pnlTest">

    <dd><a><span></span></a></dd>
</div>

This is asp.net 4


What happens if you set something to the span value, does it show up then?

...
var span = new HtmlGenericControl("span");
span.InnerHtml = "test";
link.Controls.Add(span);
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜