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

  • Home
  • SEARCH
  • 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 347473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:16:26+00:00 2026-05-12T11:16:26+00:00

I have a question about wiring web server controls. From many of the examples

  • 0

I have a question about wiring web server controls. From many of the examples that I have seen the event handler has been declared with a private access modifier. I tried doing so as shown:

    <asp:Label runat="server" ID="lblMessage" Font-Names="Verdana" Text="Hello" />
        <br />
    <asp:Button runat="server" ID="btnSubmit" text="click me!" onClick="btnSubmit_Click" />

and in the code behind file:

    private void btnSubmit_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "Goodbye";
    }

But the compiler is unable to locate the click handler unless i change the access to protected.

Should button event handlers ever be private, and if so, why did it not work in my instance?

Also, other than using the onClick property, are there any other methods for wiring event handlers to controls that are declaratively created in the .aspx file?

Thanks in advance,
Yong

  • 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-12T11:16:26+00:00Added an answer on May 12, 2026 at 11:16 am

    What might be confusing here is that many people design their web forms visually. When they want to wire a click handler to a button server control, they typically either double click the button or select it in Visual Studio, press F4 to go to its properties and set its events within that window. Either of these approaches has the following effect:

    1. A private handler is created in the code behind class. Its name is [control name]_[event]. In your case, this is btnSubmit_Click.

    2. Also in the code-behind file, each web server control has a corresponding protected member of the code behind class. In the Init even, the newly created handler is associated to the Click event on the server control by the following code:

      btnSubmit.Click += btnSubmit_Click;

    With this approach, the handler can still be private. Where you are having an issue is when you try to set the handler in the ASPX file itself. In this case, you will have to update the event handler to be non-private, as you’ve indicated, or define the following in the ASPX page itself:

    <script language="C#" runat="server">
      public void btnSubmit_Click(object sender, EventArgs e)
      {
        ..
      }
    </script>
    

    Private methods/properties of a code-behind class are not visible to the ASPX page.

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

Sidebar

Ask A Question

Stats

  • Questions 255k
  • Answers 255k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I am currently evaluating it. As compared to other javascript… May 13, 2026 at 10:24 am
  • Editorial Team
    Editorial Team added an answer Basically, the goal of serialize is to transform any (alsmost)… May 13, 2026 at 10:24 am
  • Editorial Team
    Editorial Team added an answer The following is semantically equivalent and much easier to read… May 13, 2026 at 10:24 am

Related Questions

One of the pages in our web application polls the server approximately every 10
I'm using a pre-compiled ASP.NET 2.0 site (i.e., copied to the server using the
I'm not clear about this.... When having a gridview on the View, is the
I have a double-precision floating point field in my database that stores seconds past

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.