0

我有一堆不同的面板,它们是自定义服务器控件,它们继承了 CompositeControl。面板是使用 CreateChildControls() 呈现的。我有一个页面,我根据用户从组合框中的选择来显示它们。当您更改选择时,它会为回调面板(DevExpress 控件)进行回调,这就像一个更新面板。根据选择,它将面板添加到回调面板。但似乎如果您从回调中执行此操作,则服务器控件生命周期不会开始,因此它永远不会调用 CreateChildControls() 或 OnPreRender()。关于如何使这项工作的任何想法?EnsureChildControls() 似乎没有帮助。

这是其中一个面板的一些示例代码

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

        String strParentID = this.ClientInstanceName.Length > 0 ? this.ClientInstanceName : this.ClientID;
        String strID = "";//Used as ID and ClientInstanceName.
        String strKey = "";//Used in the ID and as the ControlInfo key.

        if (!DesignMode)
        {
            //*******************************************************************

            ASPxLabel lblUnit = new ASPxLabel();
            lblUnit.Text = "Select Unit(s)";
            callbackEdit.Controls.Add(lblUnit);

            //*******************************************************************

            strKey = "btnUnitSelector";
            strID = strParentID + "_" + strKey;
            btnUnitSelector = new ASPxButton()
            {
                ID = strID,
                ClientInstanceName = strID,
                CssFilePath = this.CssFilePath,
                CssPostfix = this.CssPostfix,
                SpriteCssFilePath = this.SpriteCssFilePath,
            };

            btnUnitSelector.Width = Unit.Pixel(180);
            btnUnitSelector.AutoPostBack = false;

            this.listControlInfo.Add(new ControlInfo(strKey, btnUnitSelector.ClientInstanceName, btnUnitSelector.ClientID));
            callbackEdit.Controls.Add(btnUnitSelector);

            //*******************************************************************

            strKey = "unitPopup";
            strID = strParentID + "_" + strKey;

            unitPopup = new UnitPopup.UnitPopup();
            unitPopup.ID = strID;
            unitPopup.ClientInstanceName = strID;
            unitPopup.btnOk_AutoPostBack = false;
            unitPopup.ShowOnlyUnits = false;
            unitPopup.DataSource = GlobalProperties.Company_UnitsAndAreas;
            unitPopup.DataBind();
            btnUnitSelector.ClientSideEvents.Click = "function (s, e) { " + unitPopup.ClientInstanceName + ".Show(); }";
            unitPopup.ClientSideEvents.MemberSet = "function (s, e) { " + btnUnitSelector.ClientInstanceName + ".SetText(" + unitPopup.ClientInstanceName + ".selectedMemberName); }";

            Controls.Add(unitPopup);
            //*******************************************************************
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        ClientScriptManager cs = this.Page.ClientScript;

        //Register an embedded JavaScript file. The JavaScript file needs to have a build action of "Embedded Resource".
        String resourceName = "QSR_ServerControls.Controls.DashboardControls.SalesChart.SalesChart.js";
        cs.RegisterClientScriptResource(typeof(SalesChart), resourceName);
    }

这是添加面板的一些示例代码

    private void PopulatePanel(string panel)
    {
        tblDescCell.Controls.Add(new LiteralControl(GetPanels().Select("[PanelName] = '" + panel + "'")[0]["PanelDescription"].ToString()));
        if (panel == "SalesChart")
            tblTopLeftCell.Controls.Add(new SalesChart.SalesChart());
    }

    void callbackMain_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
    {
        PopulatePanel(e.Parameter);
    }
4

1 回答 1

0

在回调请求期间,不执行 PreRender 和 Render 方法(这是与 PostBack 请求的主要区别)。但是应该执行 CreateChildControls。请提供更多信息或代码示例。

于 2012-10-22T17:32:42.057 回答