HierarchicalDataBoundControl.PerformDataBinding is not called on postback

I am binding to SiteMapDataSource (hierarchical).

I am overriding PerformDataBinding to grab data from a data source.

Everything works fine on page load. But when I postback anywhere on the page, the PerformDataBinding method is not called, and in fact does not pass any menu items (PerformDataBinding is not called).

+2


a source to share


1 answer


Not sure why this is happening, but I have a fix. Surprisingly every HierarchicalDataBoundControl example I could find (even from msdn) did this. However, this is a workaround.



    private bool dataBound = false;
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (this.Page.IsPostBack)
        {
            this.DataBound += delegate { dataBound = true; };
            this.Page.Load += delegate { if (!dataBound) DataBind(); };
        }
    }

      

+3


a source







All Articles