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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:52:42+00:00 2026-05-22T23:52:42+00:00

This is just for a better understanding of the ASP.NET framework. When you use

  • 0

This is just for a better understanding of the ASP.NET framework. When you use a control in a declarative way (that would be web form markup), you assign event handlers by their method name using an attribute that starts with On:

<asp:Button runat="server" OnClick="..."/>

But when you look at the System.Web.UI.WebControls.Button class it has an EventHandler property named Click that the delegate is assigned to:

button.Click += new EventHandler(...);

So how is this implemented? Is that just a convention followed by the parser?

I know, it’s a strange question, the answer will do nothing but satisfy my curiosity.

  • 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-05-22T23:52:43+00:00Added an answer on May 22, 2026 at 11:52 pm

    This is a naming convention used by ASP.NET which, rather unhelpfully, looks identical to another common naming convention widely used throughout .NET. Despite the apparent similarity, these two conventions are unrelated.

    The .NET-wide convention, which turns out to be irrelevant here, is that it’s common for events to have corresponding methods that raise the event, and for those methods’ names to be formed by adding an On prefix to the event name. For example, the Click event offered by Button is related to an OnClick method, which raises that event (as has already been stated in another answer here).

    The confusing part is that the OnClick method has nothing to do with the OnClick attribute that the question concerns.

    It’s easy to demonstrate that the OnSomeEvent methods are irrelevant here by writing a control that doesn’t have any such method. Here’s the codebehind for a simple user control:

    public partial class EventWithoutMethod : System.Web.UI.UserControl
    {
        public event EventHandler Foobar;
    
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Foobar != null)
            {
                Foobar(this, EventArgs.Empty);
            }
        }
    }
    

    This declares a Foobar event. (It never actually raises it, but that doesn’t matter for the purposes of exploration.) It does not define an OnFoobar method. Nevertheless, ASP.NET is perfectly happy for us to use the OnSomeEvent convention when we use the control:

    <user:EventWithoutMethod runat="server" OnFoobar="FooHandler" />
    

    In fact, it’s not only happy for us to do that, it actually requires it. Even though my control doesn’t define any member called OnFoobar—the event is called just Foobar—I have to write OnFoobar if I want to attach the event handler from my .aspx file. If I just put a Foobar attribute in there in an attempt to attach the event, the handler will never run. (Unhelpfully, ASP.NET doesn’t generate an error when you do that, it just silently fails to do anything with the attribute, and the event handler never runs.)

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

Sidebar

Related Questions

I'm just wondering if there's a better way of doing this in SQL Server
Fairly simple; I'm just curious if there's a better way to accomplish this. Given
This question is just for my better understanding of static variables in C++. I
I'm trying to gain a better understanding of the plumbing behind ASP.NET and ASP.NET
I need a tool that I can use to get a better understanding of
I'm just wondering if it exists better solution for this. BitConverter.ToInt32(sample_guid.ToByteArray(), 0)
It doesn't really have to add newlines, just something readable. Anything better than this?
This just won't work. The problem is that I do not know enough to
This just saves time. Since I already have a web applciation. I can just
To gain a better understanding, I think it would be great to watch every

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.