views:

328

answers:

2

I have a WebPart custom control (Composite) in .Net, which gets created on page load to show a Chart using 'Dundas Charting Controls' (this is created by a user control inside the page). I get the properties for this control from the database.

I have another control, which is a Filter (outside webpart) and based on data of this filter control which the user selects and which I would get on postback after click of button, I have to show the filtered chart results. The problem is CreateChildControls() gets called before the postback data is available (which would be available only after the Page_Load event fires).

I'm unable to get this data in time to pass on the parameters for filtering the Chart Results.

The implementation os like this ...

Webparts

Page > User Control > Webparts > Composite Control/Chart

Filter

Page > User Control > Composite Control [I get this data on Postback]

A: 

It sounds like you are running into an event ordering issue. I always try to make my controles relatively dump - so they don't really know how they are being used.

Consider creating a method in your chart control to force an update of its data:

public void UpdateChart(-- arguments as needed --)

then create an event in your composit control (that has your filters) like

public event Eventhandler FiltersChanged;

Assign this to an event hander on parent page:

filterControl.FiltersChanged += new EventHandler(Filter_OnChange)

Then create an event handler that tells your chart control about the change

Filter_OnChange(Object sender, EventArgs e)
{
   // get whatever data you need from your filter control
   // tell the chart about the new data and have it reload/redraw
   myChart.UpdateData( - filter options here -}
}

In doing so, you let the page direct the order of operations and do not rely on the order in which the child controls Load methods are called.

James Conigliaro
Thanks for the answer James
Smarty
A: 

James - Thanks for your answer, but this does not seem to work in my scenario or rather I couldn't make it work, when I tried it. The controls seems to be doing too much and is getting data from every where, it has its own constructor implementation, Load() override etc so a single UpdateChart() function may not have done the trick in this case.

This is what I did, finally.

I fire an Ajax request with Filter Data and set the value in a Session Variable before page does a Postback, this way I get the data at all places/events, and pass on the same as parameter where required. I know it may seem weird way to implement this, but it saved additional Database calls (which in this case are many to create the controls again) even though it comes at the cost of an additional Server HTTP ajax request.

Let me know this implementation can have any negative impact.

Smarty