0

I have a placeholder on my ASPX Page:

<asp:PlaceHolder ID="phControlContainer" runat="server"></asp:PlaceHolder>

In the code behind on PageLoad I generate a RadHtmlChart with an ID="MyChart" and add it to the placeholder by doing the following:

phControlContainer.Controls.Add(chart);

I can see it on the page at this point.

Then on another PostBack OnButtonClick I want to modify the chart so I attempt to find it:

RadHtmlChart chart = (RadHtmlChart)phControlContainer.FindControl("MyChart");

It finds nothing and chart is null. Additionally phControlContainer.Controls.Count is zero.

Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
  • This guy seems to have found a solution for controls added dynamically: https://stackoverflow.com/a/17589598/4519548 – Rick Wolff Oct 18 '17 at 18:15
  • 1
    He is saying that dynamic controls are always lost after postback. So he had to recreate them. Can you check if that helps you? – Rick Wolff Oct 18 '17 at 18:16
  • Yes they are lost after PostBack. So you have to keep track somewhere (ViewState, Session) which controls are added and recreate them on every page load. Or do not use `Page.IsPostBack` check when adding conrols. – VDWWD Oct 18 '17 at 19:03
  • Another option is to add the chart to page statically (ASPX page using tag – DaniDev Oct 18 '17 at 19:28
  • Thanks guys I figured it out. The Telerik RadHtmlChart I am using is not stored in ViewState the way I am adding it. – Blake Rivell Oct 18 '17 at 20:34

0 Answers0