I have a problem with UpdatePanel.Update() which works initially but then stops. I have tumbled with this problem for some time and some background is needed so please read ahead.
I have an ASP.net application in which I have a subpage that display computed information in graphs. Each graph is embedded in an UpdatePanel. The graph is a user control that uses the standard asp:Chart for display.
My task is to enable this page with AJAX capabilities so the page is responsive during postbacks.
When I access this page from another page, during the initial page rendering, I use a wait dialog for each graph and a pageload event on the client side. In the client event, a hidden button is clicked which a server event handles (the hidden button is inside an UpdatePanel so the postback is asynchronous). Each graph is computed and the UpdatePanels are in turn updated with the Chart content. This is done using UpdatePanel.Update. And it is successful.
However, I also have some dynamically created RadioButtons on the page. Their purpose are to switch graph type --- to show the same data in different ways. I subscribe on each RadioButton's OnCheckedChanged event and the postback is asynchronous since the radiobuttons are inside an UpdatePanel. In the server event handler I determine the type of graph and use this as input to the Chart creation. I then remove the old Chart control from my Panel and adds the new Chart and then UpdatePanel.Update() is called. But with no success. Nothing happens, no errors, nothing. Why is this??
I think this is strange for two reasons:
- If I compute every Chart data in the initial rendering instead of using the "Wait dialog"-solution described earlier then I can select graph types successfully and all subsequent AJAX requests work as intended.
- The same code is hit in the initial rendering phase and in the radio button event handler, but it only works the first time.
Here is the method that computes the graph, adds it to the panel and updates the UpdatePanel:
public void UpdateGraph(GraphType type, GraphMapper mapper)
{
//Panel is the content of UpdatePanelGraph's <ContentTemplate>
Panel.Controls.Clear();
chart = new Chart(type, mapper); //Computation happens inside here
Panel.Controls.Add(chart);
//UpdatePanelGraph is in UpdateMode Conditional and has
//ChildrenAsTriggers set to false
UpdatePanelGraph.Update();
}
I really need a way for these radiobuttons to work, possibly using some client-side JavaScript or handling things on the server side differently. I have thought about using a JavaScript postback call on the UpdatePanel instead of the UpdatePanel.Update(). However, the issue I have here is how to notify the client side when the server side is finished with computing the graph?
An plausible explanation of the strange behavior is also much appreciated.
Any help appreciated, thanks