David Barel
David Barel

Reputation: 285

Child Control is not rendering

I created a custom composite control that contains, among other things, child controls from this project https://googlevisnet.codeplex.com/ (it is a .NET library for google charts which i checked various times). I am using VisualStudio 2012 and a simple C# Class library.

I override CreateChildControl like so:

protected override void CreateChildControls()
    {
        Controls.Clear();

        //create the pie control
        GenderChart = new GVPieChart();
        GenderChart.Width = PieChartDimentions[0];
        GenderChart.Height = PieChartDimentions[1];
        GenderChart.ChartData(GenderDistributionTable);

        //create the bar control
        AgeChart = new GVColumnChart();
        AgeChart.Width = BarChartDimentions[0];
        AgeChart.Height = BarChartDimentions[1];
        AgeChart.ChartData(AgeDistributionTable);

        this.Controls.Add(GenderChart);
        this.Controls.Add(AgeChart);
    }

and override Render like so:

AgeChart.RenderControl(output);

When I run the code on the page everything seems to work, and i can tell that the control rendered the area correctly (i can see the div with the specific size), however I do not see the chart itself.

The weird thing is that for a moment there it was working and then stopped again without me applying any changes to the code.

Any Ideas?

Upvotes: 0

Views: 977

Answers (1)

David Barel
David Barel

Reputation: 285

Apparently what solve the problem was something as stupid as adding the ID for the controls. protected override void CreateChildControls() { Controls.Clear();

        //create the pie control
        GenderChart = new GVPieChart();
        GenderChart.ID = "genderChar";
        GenderChart.Width = PieChartDimentions[0];
        GenderChart.Height = PieChartDimentions[1];
        GenderChart.ChartData(GenderDistributionTable);

        ////create the bar control
        AgeChart = new GVColumnChart();
        AgeChart.ID = "ageChart";
        AgeChart.Width = BarChartDimentions[0];
        AgeChart.Height = BarChartDimentions[1];
        AgeChart.ChartData(AgeDistributionTable);

        this.Controls.Add(GenderChart);
        this.Controls.Add(AgeChart);
    }

I don't know how i forgot something as essential as ID. Our mind stops to think simple at some point.

Cheers :)

Upvotes: 2

Related Questions