UserControl继承自另一个类以扩展它

时间:2014-09-12 10:12:22

标签: asp.net inheritance webforms user-controls

我有第三方控件 ClientPeoplePicker 。问题是无法禁用此控件。要禁用它,我将控件放在div中,位置为:relative(" 1"),并添加另一个位置:absolute和high z-index(" 2")。所以aspx结构是:

<div id="1">
 <div id=2/>
 <clientpeoplepicker/>
</div>

现在,我想创建一个用户控件,它将呈现上述所有内容并继承自ClientPeoplePicker,因此我可以使用继承,而不必将创建的ClientPeoplePicker的属性映射到控件包装器上。我怎样才能实现这一目标(最佳方式)?如果我只是在用户控件中创建一个实例,要在CreateChildControls中创建它,我将失去继承。或者我应该覆盖渲染?

1 个答案:

答案 0 :(得分:0)

好的,所以我选择了重写RenderControl

编辑:

整个代码:

    private bool _enabled = true;
    public new bool Enabled
    {
        get
        {
            return _enabled;
        }
        set
        {
            _enabled = value;
        }
    }

    Panel divWrapper;
    Panel divBlocker;

    public override void RenderControl(HtmlTextWriter writer)
    {
        divWrapper = new Panel();
        divWrapper.ID = base.ClientID + "_divWrapper";
        divWrapper.CssClass = this.CssWraper;

        divBlocker = new Panel();
        divBlocker.ID = base.ClientID + "_divBlocker";
        divBlocker.CssClass = this.CssBlocker;
        if(this.Enabled)
        {
            divBlocker.Style.Add("display", "none");
        }

        divWrapper.RenderBeginTag(writer);
        divBlocker.RenderControl(writer);

        base.RenderControl(writer);

        divWrapper.RenderEndTag(writer);
    }

CSS

.cpp_blockdiv
{
z-index: 1000;
margin: 0px;
width: 100%;
height: 100%;
background-color: #000;
opacity: 0.1;
position: absolute;
}

.cpp_container
{
position:relative;
}