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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:50:32+00:00 2026-06-17T11:50:32+00:00

I am trying to study the delegate concept in c#. I did a sample

  • 0

I am trying to study the delegate concept in c#.

I did a sample of delegate as I studied. But I did not understood the correct situation where we using its concept effectively.
Can any one please suggest a easy understandable situation where we use delegate.

I know the working of delegates. But still not cleared where it effectively use.

I posted my code below. Please let me know if any mistakes I did in the sample.

Thankx in advance.

ChangePassword.ascx

  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChangePassword.ascx.cs" Inherits="User_Controls_ChangePassword" %>

<div style="width:500px;clear:both;">
<div style="width:100%; clear:both;">
    <div style="width:150px; float:left;">
        <asp:Label ID="newPassword" runat="server" Text="New Password"></asp:Label>
    </div>
    <div style="width:100px; float:left;">
        <asp:TextBox ID="newPassText" runat="server" Width="200"></asp:TextBox>
    </div>
</div>
<div style="width:100%; clear:both;padding-top:20px;">
    <div style="width:150px; float:left;">
        <asp:Label ID="Label1" runat="server" Text="Confirm New Password"></asp:Label>
    </div>
    <div style="width:100px; float:left;">
        <asp:TextBox ID="confirmNewPass" runat="server" Width="200"></asp:TextBox>
    </div>
</div>
<div style="width:100%; clear:both;padding-top:20px;">
    <div style="width:150px; float:left;">
        <asp:Label ID="Label2" runat="server" Text="&nbsp;"></asp:Label>
    </div>
    <div style="width:207px; float:left;">
        <div style="float:left;">
            <asp:Button ID="changePass" runat="server" Text="Change"  /> 
        </div>
        <div style="float:right;">
            <asp:Button ID="cancelButton" runat="server" Text="Cancel" /> 
        </div>
    </div>
</div>
<div style="width:100%; clear:both;padding-top:20px;">
    <div style="width:350px; float:left;">
        <asp:Label ID="successMessage" runat="server" Text="Passwords Changed.." ForeColor="Red" Font-Bold="true" Visible="false"></asp:Label>
    </div>
</div>

ChangePassword.ascx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class User_Controls_ChangePassword : System.Web.UI.UserControl
{
    public delegate void ChangePasswordDelegate(object sender, ChangePasswordEventArgs e);
    public event ChangePasswordDelegate ChangePasswordEvent;

    protected void Page_Load(object sender, EventArgs e)
    {
        changePass.Click += new EventHandler(changePass_Click);
    }

    void changePass_Click(object sender, EventArgs e)
    {
        ChangePasswordEvent(sender, new ChangePasswordEventArgs(newPassText.Text, this) );
    }
}


public class ChangePasswordEventArgs : EventArgs
{
    private string _newPassword = "";
    private object _parent = null;

public string NewPassword
{
    get
    {
        return _newPassword;
    }
    set
    {
        _newPassword = value;
    }
}

public object Parent
{
    get
    {
        return _parent;
    }
    set
    {
        _parent = value;
    }
}

public ChangePasswordEventArgs()
{    }

public ChangePasswordEventArgs(string pass , object parent)
{
    _newPassword = pass;
    _parent = parent;
}

}

Default.aspx

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register TagName="ChangePasword" TagPrefix="MY" Src="~/User Controls/ChangePassword.ascx" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
     <MY:ChangePasword ID="passControl" runat="server" />
</asp:Content>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
{
    passControl.ChangePasswordEvent += new User_Controls_ChangePassword.ChangePasswordDelegate(passControl_ChangePasswordEvent);
}

void passControl_ChangePasswordEvent(object sender, ChangePasswordEventArgs e)
{
    if (e.Parent != null)
    {
        User_Controls_ChangePassword cp = (User_Controls_ChangePassword)e.Parent;
        cp.FindControl("successMessage").Visible = true;
    }
}

}

  • 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-17T11:50:33+00:00Added an answer on June 17, 2026 at 11:50 am

    Thank you Meysam. He commented on my question with a very useful link regarding delegates. Now I have a clear idea about delegates and also about EventArgs. Here is the link,

    http://www.codeproject.com/Articles/4773/Events-and-Delegates-Simplified

    Hope it will help others too.

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

Sidebar

Related Questions

I'm trying to study the WCF Web Services but I'm a bit confused about
My question is deceptively simple, but I have lost several hours of study trying
I am trying to study C, and I am running in to troubles using
I am trying to study OpenGL and I have the framework added, but I
I'm trying to self-study C using C Primer Plus from Stephen Prata and one
So I'm trying to study the assembly code of a simple C program using
I am trying to study how the REST service approach works using Jersey. I
I am new in c# development. I just trying to study the delegate feature.
I am trying to study the jquery class, but I have a hard time
I am trying to self-study both object oriented design and parallel programming using the

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.