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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:50:00+00:00 2026-06-16T02:50:00+00:00

I am creating a User Control, and I want it to know nothing about

  • 0

I am creating a User Control, and I want it to know nothing about my Database Class.

However, I need certain features from that Database Class (I need to get the Employee’s name given their Employee Number).

What I would like to do is to create something in my User Control that I can wire up in my applications that use it, much like I would wire up a Click Event or something like that.

I’ve never actually created something like this before in a C# project, so I don’t know what to call it. I would imagine it has to exist.

The function I want to call in my Database Class has this signature:

public string GetEmployeeName(int employeeNumber);

Could someone tell me what it is I am trying to do?

If it is something difficult, an example would be nice as well.

  • 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-16T02:50:01+00:00Added an answer on June 16, 2026 at 2:50 am

    You can do this using a delegate e.g. Func<TArgument, TResult>;

    Add a public field to your usercontrol:

    //A method that has an int parameter and returns a string
    public Func<int, string> GetEmployeeName;
    

    In your user control when you need to get the employee name you can use the delegate:

    string employeeName;
    if (GetEmployeeName != null)
        employeeName = GetEmployeeName(employeeNumber);
    

    You can set the delegate from the hosting page or control by doing:

    myUserControl.GetEmployeeName = GetEmployeeName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a web user control and want to get some html from a
Given that you're creating a User Control in WPF that will be displayed on
I am creating a user control in ASP.NET (using VB) that uses the autocomplete
I'm creating a comments web user control. I want to use this comments control
I have a user control that I'm creating that is using some AJAX in
I'm creating my own user control that can display n amount of images. Here
I'm creating an ASP.NET control that outputs <object> and <embed> tags. I want the
I am creating a gui widget a dll library, a class that derives from
I'm looking for a tutorial that explains creating custom usercontrols in WPF. I want
I am creating a Windows forms user control. This control has a textbox 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.