Link to home
Start Free TrialLog in
Avatar of Michael Sterling
Michael SterlingFlag for United States of America

asked on

Why does my graph lose its data?

I'm using chart director to load two graphs with data on my .aspx page. I'm having trouble holding onto the data for my 2nd graph. The graph at the top of my page seems to hold onto its data during a postback, but the graph 2nd graph loses data when the page posts back and i'm not sure why.

I load a few  drop down lists in my Page_Load event:

        if (!IsPostBack)
        {
            LoadBranches();
            LoadMetros();
            LoadRegYears();
        }

Open in new window


here is my HTML:

<%@ Page Title="Quarterly Registrations By Year" Language="C#" MasterPageFile="SiteDetailPage.master"
    AutoEventWireup="true" CodeFile="QuarterlyRegistrations.aspx.cs" Inherits="VolumeChartModMakeYear" %>

<%@ Register TagPrefix="chart" Namespace="ChartDirector" Assembly="netchartdir" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style3
        {
            text-align: right;
        }
        .style4
        {
            text-align: left;
            width: 50%;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <%--<asp:UpdatePanel ID="udpnlUsedRegs" runat="server">
                                <ContentTemplate>--%>
    <%--</ContentTemplate>
                            </asp:UpdatePanel>--%>
    <table class="style1">
        <tr>
            <td>
                <table align="center" class="style1">
                    <tr>
                        <td class="style3">
                            Select a Branch
                        </td>
                        <td class="style4">
                            <asp:DropDownList ID="ddlBranch" runat="server" OnSelectedIndexChanged="ddlBranch_SelectedIndexChanged">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="style3">
                            OR Select a Metro
                        </td>
                        <td class="style4">
                            <asp:DropDownList ID="ddlMetro" runat="server" Width="200px" OnSelectedIndexChanged="ddlMetro_SelectedIndexChanged">
                            </asp:DropDownList>
                            <asp:Button ID="btnUsedRegistrations" runat="server" OnClick="btnUsedRegistrations_Click"
                                Text="Show Graph" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <table class="style1">
                                <tr>
                                    <td>
                                        <asp:Label ID="errMsg" runat="server" Text="" Font-Bold="true" ForeColor="#CC0000" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: center">
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: center">
                                        <chart:WebChartViewer ID="WebChartViewer1" runat="server" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
                <table align="center" class="style1">
                    <tr>
                        <td>
                            <asp:UpdatePanel ID="udPnlMetro" runat="server">
                                <ContentTemplate>
                                    <table align="center" class="style1">
                                        <tr>
                                            <td>
                                                <table align="center" class="style1">
                                                    <tr>
                                                        <td class="style3">
                                                            Branch:
                                                        </td>
                                                        <td class="style4">
                                                            <asp:DropDownList ID="ddlMetroBranch" runat="server" Style="margin-left: 0px">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table align="center" class="style1">
                                                    <tr>
                                                        <td class="style3">
                                                            Reg. Year:
                                                        </td>
                                                        <td class="style4">
                                                            <asp:DropDownList ID="ddlRegYearMetro" runat="server">
                                                            </asp:DropDownList>
                                                            <asp:Button ID="btnMetro" runat="server" OnClick="btnMetro_Click" Text="Show Graph" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;
                                                <table align="center" class="style1">
                                                    <asp:Panel ID="pnlMetro" runat="server">
                                                        <tr>
                                                            <td>
                                                                <chart:WebChartViewer ID="MetroRegistrationsGraph" runat="server" />
                                                            </td>
                                                        </tr>
                                                    </asp:Panel>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                    </table>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                        <td>
                            &nbsp;<table align="right" class="style1">
                                <tr>
                                    <td>
                                        <table align="center" class="style1">
                                            <tr>
                                                <td>
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    &nbsp;
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <table align="center" class="style1">
                                            <tr>
                                                <td>
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    &nbsp;
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>
                            </table>
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>

Open in new window



I can give the code that shows how I'm getting & loading the data but I don't know how useful it would be to see that. So to summarize that code, for each graph:

in one routine I load data into some global list objects using an SQL statement
in another routine, I pull the data from the lists and put the data into arrays (the graphs require arrays to be used), that have also been declared globally and each graph uses its own set of lists and arrays
then I "activate" the graphs

The graphs don't load automatically when the page loads. The user has to make some selections from the drop downs and then click a button to kick off the processes to gather the data and then load the graphs with the data and show them.

In a effort to try to solve the problem, I wrapped my 2nd graph in an update panel and that seemed to help the problem in the sense that before i used the update panel, when ever I fired off a button to view a graph the two graphs would "toggle" (one would show, the other would disappear). I would get the same behavior if I wrapped both graphs in an update panel. At least as it stands now, the top graph always shows no matter what. but the 2nd graph disappears if the page refreshes or when ever i click the button to view data for the first graph. Any help / ideas would be appreciated.
Avatar of FarWest
FarWest

did you check the enable  viewstate property
Avatar of Michael Sterling

ASKER

@fryezz: can you expand a little bit? I'm a little slow on the "uptake". "viewstate property" of what? the graph? the page?
I think  viewstate in asp.net 4 has some  view state management changes
so you can try to make it enabled for both  graph and webpage to make sure

add this in chart tag

<asp:Chart ViewStateContent="SerializationContents" />
@fryezz: I'll try to look into that further, right now the closest property to "ViewStateContent" that my chart control has is: "ViewStateMode" and none of the options for its possible values is: "SerializationContent". :-(
@fryezz: I think the reason that property isn't available, is because I'm not using the chart control provided by ASP .NET (Visual Studio), I'm using "ChartDirector" (by Advance Software Engineering: [ASE]).
:)
I saw the prefix in your code so I thought it is asp.net chart
please check similar attribute in your control,
if the control is OCX then there is a chance of a bug in coexisting 2 controls on the same page, because of some COM limitation or proper process isolation and you can check with them for bug fix
btw
I think the workaround of using iframe for each control may work in case of ocx bug
ASKER CERTIFIED SOLUTION
Avatar of Michael Sterling
Michael Sterling
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@fryezz: and ok about the iFrame solution, I'll have to research that, as I've never used an iFrame in any of my projects.
I wish you a quick good luck (developers always need it :) )
Thank you.