Today, we will dig on simple well known concepts called Events. The simple
definition is message sent by some particular object to intimate that there is
some action will be generated.
- Publisher:
The publisher class is that which does some logic and sends or fires the events.
- Subscribers:
The Subscriber class is that which handles the sent events where they are subscribed for specific action.
Question Arises: Please Explain accordingly as per the situation of this article. ??? What does Publisher Person do and what does Subscriber Person do????
- Publisher Person Do:
- Publisher replies, I will create and specify some delegate initially.
- I will declare and specify some event based on the delegate which I have created previously.
- Then I would initiate and expect some action to be performed after I
eventually fire the event.
- Subscriber Person Do:
- Subscriber replies, I will look and received the events for which I am subscribed for.
- I will be then firing off some handlers to notify occurrence of some action towards client level.
- Eventually, it's up to my owner whether he will keep me in subscribed mode or unsubscribed mode.
Question Arises: Where Can We Actually Use This Stuff???
- You would use Events when you want to respond with many subscribers.
- You would use Events when you communicate to with specific method to expect some action need to be performed.
- You would use Events when you want to synchronize threads.
- You would use Events when client who is accessing the application expects some operation to be performed when controls on page are fired.
- You would use when you expect the delegate to respond application level basis operations.
- You would use when you want to wrap your code with some asynchronous operation.
- I think we are all now good to go and Implement Simple Event accessing C# 4.0 Ver Features.
- I would explain you in simple terms rather than taking multiple classes and making you simple concept to be complex to grasp.
Pre Requirements:
- Visual Studio 2010, ASP.NET C# 4.0, ADO.NET and CSS
- SQL Server 2008.
I have created simple webform.aspx with simple
grid on it. To enhance look and feel of App I have just created very basic CSS
and added the class to Grid.
So The Complete Code of WebForm1.aspx looks like this:
<%@
Page Language="C#"
AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication2.WebForm1"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
id="Head1" runat="server">
<title></title>
<style
type="text/css">
.grid
{
font-family:
Cambria;
font-size:
medium;
color:
#006699;
background-color:
#C0C0C0;
border:
medium solid
#008080
}
</style>
</head>
<body>
<form
id="form1" runat="server">
<div><center>
<asp:GridView
ID="GridView1" runat="server"
BackColor="White"
CssClass="grid"
BorderColor="#CCCCCC"
BorderStyle="None"
BorderWidth="1px"
CellPadding="3">
<FooterStyle
BackColor="White"
ForeColor="#000066"
/>
<HeaderStyle
BackColor="#006699"
Font-Bold="True"
ForeColor="White"
/>
<PagerStyle
BackColor="White"
ForeColor="#000066"
HorizontalAlign="Left"
/>
<RowStyle
ForeColor="#000066"
/>
<SelectedRowStyle
BackColor="#669999"
Font-Bold="True"
ForeColor="White"
/>
<SortedAscendingCellStyle
BackColor="#F1F1F1"
/>
<SortedAscendingHeaderStyle
BackColor="#007DBB"
/>
<SortedDescendingCellStyle
BackColor="#CAC9C9"
/>
<SortedDescendingHeaderStyle
BackColor="#00547E"
/>
</asp:GridView>
<br
/>
<br
/>


Akshay TeotiaPosted Nov 29, 2011, 12:17 PM
Good way to represent Access Events via Methods or Handlers.