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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:59:03+00:00 2026-05-15T21:59:03+00:00

While developing and ASP.NET application in C# or VB using Visual Studio 2005/2008/2010 (Not

  • 0

While developing and ASP.NET application in C# or VB using Visual Studio 2005/2008/2010 (Not a problem in 2003), if I create a new method automatically by double-clicking on a control in the designer or picking the new method in the code editor dropdowns (VB only), the access modifier is always protected instead of private. This is annoying because my developers have to manually change the method to private every time.

Is there are way to tell visual studio to generate all new method headers as private instead of protected?

Please do not debate the reasons for wanting my methods to be private.

  • 1 1 Answer
  • 1 View
  • 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-15T21:59:04+00:00Added an answer on May 15, 2026 at 9:59 pm

    This can’t work for the case where you double-click a control in the designer.

    Double clicking a control in the designer not only creates in code-behind the code for the handler for the default event, it also changes the markup to refer to it. For instance, having added a Button to a web page, then double-clicking on it, I get:

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Yes" />
    

    If I change the visibility of Button1_Click to “private”, then I get a yellow screen of death:

    Compiler Error Message: CS1061: ‘ASP.default_aspx’ does not contain a definition for ‘Button1_Click’ and no extension method ‘Button1_Click’ accepting a first argument of type ‘ASP.default_aspx’ could be found (are you missing a using directive or an assembly reference?)

    The ASP.NET page is parsed and built to generate a class that derives from your codebehind class. That class needs to be able to reference things like your event handler.


    Apparently, when used with VB.NET, this problem does not exist. The difference is that in VB.NET, the designer does not change the markup at all, so the class generated from the markup does not need to refer to the created event handler. It can safely be made Private.

    However, since the designer, when used with C# does modify the markup such that the generated class does need to refer to the new event handler. In this case, the event handler cannot be made private.

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

Sidebar

Related Questions

I am developing one web application using asp.net 2005 and Microsoft SQL Server 2008
I am using Microsoft Visual Studio 2010 Professional and developing an asp.net / C#
While developing ASP.net applications on a Windows 7 machine in Visual Studio. Sometimes I
I am developing an application using ASP.NET (C#) and SQLServer 2008. In my database
Can I avoid using MS AJAX completely while developing ASP.NET Webforms applications and use
I am developing an application using ASP.NET MVC 1 and VS2008. When I deploy
I'm trying to understand the Repository Pattern , while developing an ASP.NET MVC application
I'm developing an asp.net (classic) application trying to implement the MVP pattern using this
I am developing a web application using Asp.net mvc framework with concept of sub
I'm developing a small web application in ASP.Net (framework version 3.5) using VS2008 and

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.