This is a migrated thread and some comments may be shown as answers.

radchart not binding properly on postback

2 Answers 131 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Sagar
Top achievements
Rank 1
Sagar asked on 21 May 2013, 10:19 PM
I have a rad chart which is throwing a java script error on a postback. here is the code:

<telerik:RadHtmlChart Width ="400px" ChartTitle-Appearance-TextStyle-FontSize ="12px" Font-Size ="12px" Skin = "WebBlue"  ID = "chartReportsAll" runat ="server" Transitions ="true">
                <PlotArea>
                    <Series>
                        <telerik:ColumnSeries DataFieldY = "TotalAmount" Name = "Test" ></telerik:ColumnSeries>                
                    </Series>
                    <XAxis DataLabelsField = "Name" Name = "test2">
                        <TitleAppearance Text="Campaign Name">
                            <TextStyle FontSize = "12px" />
                        </TitleAppearance>
                    </XAxis>
                    <YAxis>
                        <TitleAppearance Text="Amount Donated">
                            <TextStyle Margin="20" FontSize = "12px"/>
                        </TitleAppearance>
                    </YAxis>
                </PlotArea>           
            </telerik:RadHtmlChart 

And here is the code behind:

chartReportsAll.DataSource = tb2
chartReportsAll.DataBind()


The first time everything is fine. The chart shows correct data. I also have a button on this page which does a does a postback and some changes to the inputs of the graphs. After the postaback, i am getting a 

Microsoft JScript runtime error: Expected ']'

at

{var c=eval(this._dataSource); ( a dynamic page)

and when i see the datasource it is showing as:

[[{"TotalAmount":1000,"campaignID":2,"Name":"Annual Fund"},
{"TotalAmount":300,"campaignID":3,"Name":"Library Fund"}]

{"TotalAmount":1000,"campaignID":2,"Name":"Annual Fund"},
{"TotalAmount":83,"campaignID":1,"Name":"Athletics Fund"},
{"TotalAmount":300,"campaignID":3,"Name":"Library Fund"}]


The first two lines is the data before the postback and the next 3 after the postback. So the problem here is the radchart is not clearing its datatsource. It is also remembering the prrevious one. Can any one please give me a solution ? Thanks.

2 Answers, 1 is accepted

Sort by
0
msigman
Top achievements
Rank 2
answered on 22 May 2013, 07:24 PM
If you're setting the DataSource after every PostBack, you can safely disable the ViewState.  That should solve the issue you're having and give a small performance boost as well.

chartReportsAll.EnableViewState = false;
0
Sagar
Top achievements
Rank 1
answered on 23 May 2013, 12:53 PM
Thanks worked.
Tags
Chart (Obsolete)
Asked by
Sagar
Top achievements
Rank 1
Answers by
msigman
Top achievements
Rank 2
Sagar
Top achievements
Rank 1
Share this question
or