locked
I have a hidden/collapsed control; how can I ONLY load data when the control is not hidden/collapsed? RRS feed

  • Question

  • I've cycled through all the "On" methods of the chart (OnInit, OnLoad, OnPrerender, etc), and they all load data all the time.  The only thing I can think to do, is check the state of the chart -- is it collapsed or actually being displayed?  In the codebehind, I could then check to see if displayed, and if so execute the query call. The problem is the visible property for the chart shows True regardless if it's collapsed or not, so how can I check t see if it's truly collapsed?

    My .asp looks like this:

                    <div runat="server" id="divFA1" class="accordion-body collapse out">
                        <div runat="server" class="accordion-inner">
                            <hr style="background: Black; padding: 0px; height: 1px" />
                            &nbsp;&nbsp;&nbsp;<strong>SUCCESS MEASURES:</strong>
                            <ol runat="server">
                                <li runat="server">
                                    <div runat="server" class="accordion" id="accFA1SM1">
                                        <div runat="server" class="accordion-group">
                                            <div runat="server" class="accordion-heading">
                                            <a id="aFA1SM1" runat="server" style="color: Black" class="accordion-toggle" 
                                               data-toggle="collapse" data-parent="#accFA1SM1" href="#divFA1SM1">Increase 
                                               <strong>achievement</strong> total by level as measured by the state assessments.
                                            </a>
                                            </div> 
                                            <div id="divFA1SM1" runat="server" class="accordion-body collapse out">
                                                <div id="divchFA1SM1" runat="server" class="accordion-inner">
                                                    <asp:Chart ID="chAchievement" runat="server" DataMember="DefaultView" Height="350px"
                                                        Width="650px" OnPreRender="LoadGraphFA1SM1">
                                                        <Series>
                                                            <asp:Series ChartArea="chaAchievement" Legend="Legend1" Name="Series1">
                                                            </asp:Series>
                                                            <asp:Series ChartArea="chaAchievement" Legend="Legend1" Name="Series2">
                                                            </asp:Series>
                                                        </Series>
                                                        <ChartAreas>
                                                            <asp:ChartArea Name="chaAchievement">
                                                            </asp:ChartArea>
                                                        </ChartAreas>
                                                        <Legends>
                                                            <asp:Legend Name="Legend1">
                                                            </asp:Legend>
                                                        </Legends>
                                                    </asp:Chart>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </li>
    

    My codebehind looks like this:

            protected void LoadGraphFA1SM1(object sender, EventArgs e)
            {
                SqlDataSource conn = new SqlDataSource();
    
                conn.ConnectionString = "Data Source=E275RD4;Initial Catalog=DistrictAssessmentDW;Integrated Security=True;Persist Security Info=True;User ID=JEFFERSON\\jgensl1;Password=nwo4life";
                conn.SelectCommand = "exec sp_rptKPREP_Achievement @year";
    
                conn.SelectParameters.Add("year", TypeCode.String, "-2");
                DataView dvLastYear = (DataView)conn.Select(DataSourceSelectArguments.Empty);
    
                conn.SelectParameters[0].DefaultValue = "-1";
                DataView dvPriorYear = (DataView)conn.Select(DataSourceSelectArguments.Empty);
    
                //Chart Area
                chAchievement.ChartAreas[0].BackColor = System.Drawing.Color.GhostWhite;
                chAchievement.ChartAreas[0].ShadowColor = System.Drawing.Color.Red;
                chAchievement.ChartAreas[0].Area3DStyle.Enable3D = false;
                chAchievement.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
                chAchievement.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
    
                //Chart Title
                chAchievement.Titles.Add("Focus Area 1: Increased Learning");
                chAchievement.Titles.Add("Success Measure 1: Increase Achievement Total");
                chAchievement.Titles[0].Font = new System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Bold);
                chAchievement.Titles[1].Font = new System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Bold);
    
                //Series
                chAchievement.Series[0].Name = dvLastYear[0]["endYear"].ToString();
                chAchievement.Series[0].Points.DataBindXY(dvLastYear, "schoolLevel", dvLastYear, "Achievement");
                chAchievement.Series[0].IsValueShownAsLabel = true;
                chAchievement.Series[0].LabelFormat = "0.0";
                chAchievement.Series[0].Font = new System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Bold);
    
                chAchievement.Series[1].Name = dvPriorYear[0]["endYear"].ToString();
                chAchievement.Series[1].Points.DataBindXY(dvPriorYear, "schoolLevel", dvPriorYear, "Achievement");
                chAchievement.Series[1].IsValueShownAsLabel = true;
                chAchievement.Series[1].LabelFormat = "0.0";
                chAchievement.Series[1].Font = new System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Bold);
    
                chAchievement.DataBind();
            }
    
    Sunday, January 12, 2014 10:08 PM