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 8000857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:55:47+00:00 2026-06-04T15:55:47+00:00

I’ve been wondering this for a while now; but especially more so since I’ve

  • 0

I’ve been wondering this for a while now; but especially more so since I’ve been more focused on front-end development for the last few weeks. It might sound like a broad question, but hopefully there’s an answer, or a reason as to:

Why aren’t .NET web control event handlers generic?

Reasoning

The reason I ask, is due to the nicety and elegance of strongly typed event handlers. Throughout my project, wherever required, I tend to use the .NET generic EventHandler<T> delegate, which has been around since .NET 2.0; as discussed here.

public delegate void EventHandler<TArgs>(object sender, TArgs args) where TArgs : EventArgs

It would be relatively straight forward to expand on this, and to define a type for the sender as well, something like so.

public delegate void EventHandler<TSender, TArgs>(TSender sender, TArgs args) where TArgs : EventArgs

Whenever working with .NET controls, occassionally I find myself binding the event handler in the code-behind rather than the ASPX file, and then having to cast the object to the desired type if I need to do any additional checks or alterations.

Existing

Definition

public class Button : WebControl, IButtonControl, IPostBackEventHandler
{
    public event EventHandler Click;
}

Implementation

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.MyButton.Click += new EventHandler(MyButton_Click);
}

protected void MyButton_Click(object sender, EventArgs e)
{
    // type cast and do whatever we need to do...
    Button myButton = sender as Button;
}

Generic

Definition

public class Button : WebControl, IButtonControl, IPostBackEventHandler
{
    public event EventHandler<Button, EventArgs> Click;
}

Implementation

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.MyButton.Click += new EventHandler(MyButton_Click);
}

protected void MyButton_Click(Button sender, EventArgs e)
{
    // no need to type cast, yay!
}

I know it’s a relatively small change, but surely it’s more elegant? 🙂

  • 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. Editorial Team
    Editorial Team
    2026-06-04T15:55:49+00:00Added an answer on June 4, 2026 at 3:55 pm

    Because it’s old.

    The web controls were developed for .NET 1.0, and generics didn’t arrive until .NET 2.0.

    Of course the controls could have been changed, but that means that all old code would need to be changed to compile (and they would need to be recompiled as the old binaries wouldn’t work any more), and all old examples (millions of web pages) would be obsolete.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.