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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:46:28+00:00 2026-05-23T19:46:28+00:00

I use asp.net and c# in web forms. Using Visual Studio it creates automatically

  • 0

I use asp.net and c# in web forms.

Using Visual Studio it creates automatically Event Handlers Methods for my controls.
VS generate the Method name in this way idControl_event. I know I can give any name to Event Handlers Methods.

  • So I’m wondering what is your favorite approach at naming theme.

  • I would like to know if using Web Forms is possible to write Event Handlers Method in a separate class (not in code behind for a specific web page) and how to call theme from the Control.

Thanks for your time.

  • 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-23T19:46:28+00:00Added an answer on May 23, 2026 at 7:46 pm

    For event handler names, I generally use the format that Visual Studio generates by default: [idControl]_[eventName]. But that is very much a personal/team preference. I’ve seen similar discussions about this such as this one or this one. Regardless of how you choose to name the event handlers, I think the most important thing is to remain consistent.

    As for having the event handlers outside of your code behind, I haven’t seen this done very often but it is possible. The easiest way would be to have a static method in the separate class with the common event handling logic. For example, here is how you could have standard logic for Page.Loaded in a separate class. I believe you’ll need to register the event handler via code – I don’t think you can do it in markup (aspx).

    public static class CommonEventHandlers
    {
        public static void Page_Loaded(object sender, EventArgs e)
        {
            //Do any standard logic
    
            //If you need a reference to the page that raised the event, 
            //   you can get it from the 'sender' parameter.
            Page page = (Page)sender;
    
            //Do something with 'page'
        }
    }
    

    Then in the code-behind of the page that you want to use that common event handler:

    public partial class WebForm1 : System.Web.UI.Page
    {
        public WebForm1()
        {
            //Register the handler via code in the constructor
            Load += CommonEventHandlers.Page_Loaded;
        }
    }
    

    As another option, you could use inheritance to help with code reuse. For example, you could have a base class that your Pages inherit from that has standard handlers. One benefit of this is that you can register event handlers in markup even if the method is declared in a base class so you don’t need to do anything in the code-behind of the ancestor page.

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

Sidebar

Related Questions

I use the ASP.NET Development Web server (also known as the Visual Studio Development
I use the ASP.NET validation controls in an ASP.NET web forms environment. Is the
I'm trying to use SWFUpload with an ASP.NET Web Forms project. I need to
When building a multi-lingual website (with ASP.NET web forms), I'll use an HTTP module
I use ASP.NET and WCF services in a load balanced web server environment, using
I need my ASP.NET web application to use silverlight controls in my web page.
I create new ASP.NET web application that use SMTP to send message. The problem
Suppose you have two seperate ASP.NET Web Application projects that both need to use
I'm working on an asp.net web site. We have to use com interop to
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint

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.