Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 143779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:08:57+00:00 2026-05-11T08:08:57+00:00

I have a _Click event that is firing when a chart is clicked on.

  • 0

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); } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:08:58+00:00Added an answer on May 11, 2026 at 8:08 am

    I’m not sure what else can be done about casting sender to a chart (other than using as), but there are many ways to deal with the associated controls problem.

    • Add a property to the Chart called ‘LinkedPanel’ and assign your update panel to it

      You’ll see a similar pattern used in a notification icon, where you associate it with a context menu)

      I think this is particularly nice, because when it’s done right you can just assign the linked control in the form designer. (Of course it won’t help with your dynamically generated controls)

    • Combine both controls into a single UserControl (if the controls always show right next to each other, this might be the right thing to do)

    • Create an object that knows about both controls, and have it handle the events that they raise

    I agree that depending on the name just feels wrong; I’d be too embarassed/nervous to use it in production code :-/ (If you’re the only developer, then I guess it’s up to you…)

    Using these other approaches makes it less likely that an ‘innocent change’ made by another developer is going to start causing unexpected exceptions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a menu click event that looks something like this.... Public Sub ToolbarManager_ToolClick(sender
I have a onclick event that is like: public void OnMyButton_Click(object sender, EventArgs e)
I have a click event that does this: $('table tbody td').click( function (e) {
On page1.php I have a click event that causes the user to be redirected
I have a button click event that takes information from controls and enters it
I have an image with a click event handler that captures the location where
It seems that the WPF Rectangle shape does not have the Click event defined.
I have found that dragend event in Google Map also trigger the click event
I have a clip that catches the click event using on(release) { .... }
I have a local thread that is started on button-click event from the main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.