0

我正在创建一个复合控件类,其中包含多个 devexpress aspx 控件。但是,设计时存在一个问题:每当我更改我公开的子控件属性时,子控件都会丢失其界面/皮肤(如下图) 在此处输入图像描述 上图显示,leftlistbox,底部两个按钮是 aspx控件,而 rightlistbox 是 asp 控件。每当我访问并更改复合控件的子控件属性时,只有那些 devexpress 控件会在设计时丢失其界面/外观,如上所示。下面是我的复合控件类文件。

   [ParseChildren(true), PersistChildren(false)]
public class CompositeControl_TEST : CompositeControl, INamingContainer 
{
    private ASPxListBox leftListBox;
    private ListBox rightListBox;
    private ASPxButton lefttoright;
    private ASPxButton righttoleft;

    [Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), RefreshProperties(RefreshProperties.Repaint), NotifyParentProperty(true)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public DevExpress.Web.ASPxEditors.ASPxListBox XF_leftListBox
    {
        get
        {
            this.EnsureChildControls();
            return leftListBox;
        }
    }

    [Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), RefreshProperties(RefreshProperties.Repaint), NotifyParentProperty(true)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ListBox XF_rightlistBox
    {
        get
        {
            this.EnsureChildControls();
            return rightListBox;
        }
    }

    [Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), RefreshProperties(RefreshProperties.Repaint), NotifyParentProperty(true)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public DevExpress.Web.ASPxEditors.ASPxButton XF_left2rightButton
    {
        get
        {
            this.EnsureChildControls();
            return lefttoright;
        }
    }

    [Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), RefreshProperties(RefreshProperties.Repaint), NotifyParentProperty(true)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public DevExpress.Web.ASPxEditors.ASPxButton XF_right2leftButton
    {
        get
        {

            this.EnsureChildControls();
            return righttoleft;
        }
    }

    protected override void RecreateChildControls()
    {    
        base.EnsureChildControls();
    }

    protected override void CreateChildControls()
    {
        this.Controls.Add(new LiteralControl(@"<div>"));
        this.Controls.Add(new LiteralControl(@"<table>"));
        this.Controls.Add(new LiteralControl(@"<tr>"));

        this.Controls.Add(new LiteralControl(@"<td>"));
        this.leftListBox = new ASPxListBox();
        this.leftListBox.ID = this.ClientID + "leftListBox";
        this.leftListBox.Items.Add("left from cs");
        this.Controls.Add(leftListBox);
        this.Controls.Add(new LiteralControl(@"</td>"));

        this.Controls.Add(new LiteralControl(@"<td>"));
        this.rightListBox = new ListBox();
        this.rightListBox.ID = this.ClientID + "rightListBox";
        //this.rightListBox.Items.Add("Right from cs");
        this.Controls.Add(rightListBox);
        this.Controls.Add(new LiteralControl(@"</td>"));
        this.Controls.Add(new LiteralControl(@"</tr>"));

        this.Controls.Add(new LiteralControl(@"<tr>"));
        this.Controls.Add(new LiteralControl(@"<td>"));
        this.lefttoright = new ASPxButton();
        lefttoright.ID = this.ClientID + "lefttoright";
        lefttoright.Text = "lefttoright";
        this.Controls.Add(lefttoright);
        this.Controls.Add(new LiteralControl(@"</td>"));

        this.Controls.Add(new LiteralControl(@"<td>"));
        this.righttoleft = new ASPxButton();
        righttoleft.ID = this.ClientID + "righttoleft";
        righttoleft.Text = "righttoleft";
        this.Controls.Add(righttoleft);
        this.Controls.Add(new LiteralControl(@"</td>"));
        this.Controls.Add(new LiteralControl(@"</tr>"));
        this.Controls.Add(new LiteralControl(@"</div>"));
        base.CreateChildControls();
    }
}

}

我一直在网上搜索类似的问题,但似乎没有找到任何匹配的问题。

4

2 回答 2

1

我知道这很旧,但我想我会加入。您必须重写设计器类 CompositeControlDesigner 作为默认调用 RecreateChildControls - 由于控件属性未保存在 viewState 中,因此在此方法调用期间会重新创建它们

[Bindable(true),   DesignerSerializationVisibility(DesignerSerializationVisibility.Content), RefreshProperties(RefreshProperties.Repaint), NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public DevExpress.Web.ASPxEditors.ASPxButton XF_right2leftButton
{
    get
    {

        this.EnsureChildControls();
        //this is not in viewsate and it is ill adviced to try and put it there. 
        return righttoleft;
    }

}

尝试创建从 CompositeControlDesigner 派生的设计器然后像这样分配给您的自定义控件

[
Designer("YourDesignerNamespace.YourCompositeControlDesigner, " + YourAssemblyInfo)
] 
[ParseChildren(true), PersistChildren(false)]
public class CompositeControl_TEST : CompositeControl, INamingContainer 
{....

}

像这样覆盖 CompositeControlDesigner 中的 CreateChildControls

protected override void CreateChildControls()
    {

    }

这将通过接口属性删除对 RecreateChildControl 的调用

或者,您可以覆盖 GetDesignTimeHtml - 如果您不打算调用 base.GetDesignTimeHtml(此方法调用 CreateChildControls),这显然是。这必须处理 Html(您只需在 ViewControl 上调用 RenderControl 即可);

于 2013-07-01T01:20:37.863 回答
0

发生这种情况是因为您没有覆盖处理控件的设计时修改的设计器。由于您正在覆盖主要功能,因此可以保证控件仍然正常运行。也许,通过 WebUserControl 组织这样一个复杂的布局会更好......

于 2012-05-03T22:04:16.783 回答