Events and delegates in C# Part 108

  • دعنا نشارك هذا :
ترتيب الدرس : 108
المدة : 00:14:57
التحكم :
Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.


All ASP .NET Text Articles

All ASP .NET Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In this video we will discuss about raising another custom event from CalendarUserControl. If you have not watched Parts 106 and 107, I would strongly encourage you to do so before continuing with this video. In this part, we will discuss about raising DateSelected custom event, whenever, the user selects a "Date" from the "CalendarUserControl".

The following are the steps to raise this event
Step 1: Create "DateSelectedEventArgs" class that will contain the event data.
public class DateSelectedEventArgs : EventArgs
private DateTime _selectedDate;

public DateSelectedEventArgs(DateTime selectedDate)

public DateTime SelectedDate
return this._selectedDate;

Step 2: Create DateSelectedEventHandler delegate.
public delegate void DateSelectedEventHandler(object sender, DateSelectedEventArgs e);

Step 3: Create DateSelected event.
public event DateSelectedEventHandler DateSelected;

Step 4: Create a protected virtual method "OnDateSelection" to raise the event.
protected virtual void OnDateSelection(DateSelectedEventArgs e)
if (DateSelected ! null)
DateSelected(this, e);

Step 5: Finally raise the event, whenever a date is selected from the CalendarUserControl.
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
DateSelectedEventArgs dateSelectedEventDatanew DateSelectedEventArgs(Calendar1.SelectedDate);

// Rest of the code

For the HTML and code samples used in the demo please visit my blog at the following link

سيتم تفعيل التعليقات قريبا

Sep 23, 2020 07:32:26