在自定义的控制了Itemplate的使用 [英] Usage of ITemplate in custom control

查看:97
本文介绍了在自定义的控制了Itemplate的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚,如果我可以在自定义控制使用了Itemplate 接口。这是我到目前为止已经完成。

I'm trying to figure out if I can use the ITemplate interface in a custom control. Here is what I've done so far.

public class Tooltip : Control
{
    public ITemplate ContentTemplate { get; set; }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        var ctrl = new HtmlGenericControl("a");

        if (ContentTemplate != null)
        {
            ContentTemplate.InstantiateIn(ctrl);
        }

        this.Controls.Add(ctrl);
    }
}

在asp.net控制使用

The asp.net control usage

<gc:Tooltip runat="server">
    <ContentTemplate>
        hello
    </ContentTemplate>
</gc:Tooltip>

的想法是,它应该返回像这样

The idea is that it should return something like this

<a>hello</a>

但结果看起来像这样

But the result looks like this

<ContentTemplate>
  hello
</ContentTemplate>
<a></a>

但包含模板标签和似乎忽略不管我做什么。

It does include the template tags and seem to ignore whatever I do.

任何意见是pciated AP $ P $

Any advice is appreciated

推荐答案

我是从错误的类继承,切换到WebControl的它开始工作时

I was inheriting from the wrong class, when switching to WebControl it started working

public class Tooltip : WebControl

这篇关于在自定义的控制了Itemplate的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆