views:

368

answers:

1

Im using VS 2005 and I want to find the best way to create a Dundas chart dynamically. In my codebehind, I have a procedure that creates the markup tags for a Dundas chart. When the page renders, it doesnt display anything but the view code shows the tags for the chart.

I know its probably something with the rendering of html in the whole .net process. What is the best way to do this? Ive created dynamic controls in various ways, but this seems to be a little different since Im building a string and then trying to render. Below is the basic code that is run when a user clicks a button on the page.

    string dundasXML = "";

    dundasXML = "<DCWC:CHART id='Chart1' runat='server' RenderType='InputTag' ImageType='Png' >";
    dundasXML += "<Series>";
    dundasXML += "<dcwc:Series ChartType='SplineArea' Name='Series1'>";
    dundasXML += "<Points>";
    dundasXML += "<dcwc:DataPoint YValues='6'></dcwc:DataPoint>";
    dundasXML += "<dcwc:DataPoint YValues='9'></dcwc:DataPoint>";
    dundasXML += "<dcwc:DataPoint YValues='3'></dcwc:DataPoint>";
    dundasXML += "</Points>";
    dundasXML += "</dcwc:Series>";
    dundasXML += "</Series>";
    dundasXML += "<ChartAreas>";
    dundasXML += "<dcwc:ChartArea BorderColor='' Name='Default' BackColor='Transparent'>";
    dundasXML += "</dcwc:ChartArea>";
    dundasXML += "</ChartAreas>";
    dundasXML += "</DCWC:CHART>";

    LiteralControl l = new LiteralControl(dundasXML);

    myPanel.Controls.Add(l);
+1  A: 

You can use the ParseControl method to generate a control from markup.

You will need to inject the required @Register directive before your markup when parsing the control. See this article for an explanation of how to do this.

pmarflee
I tried that and got "Unknown server tag 'DCWC:CHART'"Im not sure why I would get this since the directive at the top of my page is <%@ Register Assembly="DundasWebChart" Namespace="Dundas.Charting.WebControl" TagPrefix="DCWC" %>
rahkim
See my updated answer for an explanation of how to get the control namespace recognized.
pmarflee
It looks like you just need to add the directive into the string.
rahkim