I have a _Click event that is firing when a chart is clicked on. In this event I immediately cast the sender to type Chart. I often follow this paradigm but feel icky each time that I do.
In this particular instance I am also immediately running out to find a corresponding UpdatePanel so I can add a dynamically rendered GridView to it. The Chart and UpdatePanel are cobbled together by having similar IDs. Both the chart and updatepanel are dynamically created at runtime.
I am wondering if there is a better/preferred way to implement this sort of behavior.
protected void Chart_Click(object sender, ImageMapEventArgs e)
{
Chart chart = (Chart)sender;
UpdatePanel up = (UpdatePanel)chart.Parent.FindControl(chart.ID + "UP");
GridView gv = new GridView();
Dictionary<string, string> displayFields =
new Dictionary<string, string>();
// add data to displayFields by using the ImageMapEventArgs.PostBackValue
// to create data for dictionary ...
gv.DataSource = displayFields;
gv.DataBind();
up.ContentTemplateContainer.Controls.Add(gv);
}